From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965163AbcFMKHc (ORCPT ); Mon, 13 Jun 2016 06:07:32 -0400 Received: from out4133-50.mail.aliyun.com ([42.120.133.50]:10434 "EHLO out4133-50.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964862AbcFMKHa (ORCPT ); Mon, 13 Jun 2016 06:07:30 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03306;MF=hillf.zj@alibaba-inc.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_----4v8si9S_1465812429; Reply-To: "Hillf Danton" From: "Hillf Danton" To: "'Minchan Kim'" Cc: "linux-kernel" , References: <040501d1c55a$81d51910$857f4b30$@alibaba-inc.com> In-Reply-To: <040501d1c55a$81d51910$857f4b30$@alibaba-inc.com> Subject: Re: [PATCH v1 3/3] mm: per-process reclaim Date: Mon, 13 Jun 2016 18:07:09 +0800 Message-ID: <040601d1c55b$5934e6b0$0b9eb410$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQDoDjCTKW3wBRVSKa6Unt8yqIwSYqG6mOwA Content-Language: zh-cn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +static ssize_t reclaim_write(struct file *file, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + struct task_struct *task; > + char buffer[PROC_NUMBUF]; > + struct mm_struct *mm; > + struct vm_area_struct *vma; > + int itype; > + int rv; > + enum reclaim_type type; > + > + memset(buffer, 0, sizeof(buffer)); > + if (count > sizeof(buffer) - 1) > + count = sizeof(buffer) - 1; > + if (copy_from_user(buffer, buf, count)) > + return -EFAULT; > + rv = kstrtoint(strstrip(buffer), 10, &itype); > + if (rv < 0) > + return rv; > + type = (enum reclaim_type)itype; > + if (type < RECLAIM_FILE || type > RECLAIM_ALL) > + return -EINVAL; > + > + task = get_proc_task(file->f_path.dentry->d_inode); > + if (!task) > + return -ESRCH; > + > + mm = get_task_mm(task); > + if (mm) { > + struct mm_walk reclaim_walk = { > + .pmd_entry = reclaim_pte_range, > + .mm = mm, > + }; > + > + down_read(&mm->mmap_sem); > + for (vma = mm->mmap; vma; vma = vma->vm_next) { > + reclaim_walk.private = vma; > + > + if (is_vm_hugetlb_page(vma)) > + continue; > + > + if (!vma_is_anonymous(vma) && !(type & RECLAIM_FILE)) > + continue; > + > + if (vma_is_anonymous(vma) && !(type & RECLAIM_ANON)) > + continue; > + > + walk_page_range(vma->vm_start, vma->vm_end, > + &reclaim_walk); Check fatal signal after reclaiming a mapping? > + } > + flush_tlb_mm(mm); > + up_read(&mm->mmap_sem); > + mmput(mm); > + } > + put_task_struct(task); > + > + return count; > +}