From patchwork Wed Feb 12 23:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11379363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D49E139A for ; Wed, 12 Feb 2020 23:40:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5E7E72168B for ; Wed, 12 Feb 2020 23:40:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ugnk4mbC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E7E72168B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 21C686B04D1; Wed, 12 Feb 2020 18:40:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0B81B6B04D3; Wed, 12 Feb 2020 18:40:02 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E99736B04D4; Wed, 12 Feb 2020 18:40:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id CE3E16B04D1 for ; Wed, 12 Feb 2020 18:40:01 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7159C824805A for ; Wed, 12 Feb 2020 23:40:01 +0000 (UTC) X-FDA: 76483095402.15.verse35_748aeccd7d43b X-Spam-Summary: 2,0,0,b9fbfe83be2e5426,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-api@vger.kernel.org:oleksandr@redhat.com:surenb@google.com:timmurray@google.com:dancol@google.com:sspatil@google.com:sonnyrao@google.com:bgeffon@google.com:mhocko@suse.com:hannes@cmpxchg.org:shakeelb@google.com:joaodias@google.com:joel@joelfernandes.org:alexander.h.duyck@linux.intel.com:minchan@kernel.org,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3867:4118:4250:4385:5007:6119:6261:6642:6653:6742:7903:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13868:13894:14096:14181:14394:14721:21080:21444:21451:21627:21990:30054:30070,0,RBL:209.85.214.195:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MS BL:0,DNS X-HE-Tag: verse35_748aeccd7d43b X-Filterd-Recvd-Size: 7842 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 23:40:00 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id p11so1544573plq.10 for ; Wed, 12 Feb 2020 15:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tK/qyDb2GX3eOsQv+8LykkGI1WZNv+AWZfoVVRiylFw=; b=ugnk4mbCpyLdbSnvSLG+4LE+l7uQjSspFTFdoXumnT9VtWq0fApfN4PwLFAP90qoof my+fCb7um1UNKkVcQdS2Fy2CxJIvpngIkgvSrCwcCeP+rS9OAZOpRZjv+YLq/FZj+YU6 p3hj4WL+PtezT3ZPgcOlwn9B3TR3+L4h0YclrXkhWtBMF46MqTSO7Nwuji88u0C9Ys9I Victfq0Q7S8GZ3z/WzMRtXU0sMlhPBiNmTzTa96CahdBEIyJw/QeiUCPOtn1bxydOGgY TBqqxdcWMBLx95yG//Tr7q3kXPK7/xDqjdZ7j+UaU3pTyktPWgY6/MvqDY5EfO60bb3s Bx9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=tK/qyDb2GX3eOsQv+8LykkGI1WZNv+AWZfoVVRiylFw=; b=RBKOE4oMaeOjeUDiLDJyIIDD1HlRNvQ0OWPONm2oWtZa6cSzCJd9i/T/GJSJgDGQXw xyQZ91hZAQonI3ae5jQflUafmVELhiksZuUys/mUxhqRQrmE3RCyavT4kso4rTx8EETa EUtJe4FCdNM+fLXGvQuJCBEzF+rI4XqW1FtAEl2eLgJ2BD29uZ+VRKMX5N6TUf/dL2z0 9y6tcmyb9J215f1X4LDlq3OCxybhydemlvZ0AAXVmxk3WJIn22OxRVSr3KmEG8EeifE6 C9DiDQIio3WUveOdN7D0t/7s+Klo7YXFmMczrvJRS7bCV8ZlgJ8szeABan4zUrDOTAKF b7ww== X-Gm-Message-State: APjAAAWnJX/uvyiYuBQlFDRJw4aRDdGXWEqzi4WpKWsGiUhBIfa8baLO 99RktrdWvbmBUfE4LQ85+a0= X-Google-Smtp-Source: APXvYqzEB9/J7b1QjW8h1fUyP6Qmptb0s33s1keuBeCMZm1l7u56kP5ukjXfiNoaeQnUfZEkSg508w== X-Received: by 2002:a17:902:8bc1:: with SMTP id r1mr10844147plo.279.1581550799359; Wed, 12 Feb 2020 15:39:59 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id k5sm296664pju.29.2020.02.12.15.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 15:39:58 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , Alexander Duyck , Minchan Kim Subject: [PATCH v4 4/8] mm: check fatal signal pending of target process Date: Wed, 12 Feb 2020 15:39:42 -0800 Message-Id: <20200212233946.246210-5-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog In-Reply-To: <20200212233946.246210-1-minchan@kernel.org> References: <20200212233946.246210-1-minchan@kernel.org> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Bail out to prevent unnecessary CPU overhead if target process ha pending fatal signal during MADV_COLD| MADV_PAGEOUT operation. Signed-off-by: Minchan Kim --- mm/madvise.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index bb04c7897eb9..276b9d81c1dd 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -36,6 +36,7 @@ struct madvise_walk_private { struct mmu_gather *tlb; bool pageout; + struct task_struct *task; }; /* @@ -316,6 +317,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (fatal_signal_pending(current)) return -EINTR; + if (fatal_signal_pending(private->task)) + return -EINTR; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (pmd_trans_huge(*pmd)) { pmd_t orig_pmd; @@ -471,12 +475,14 @@ static const struct mm_walk_ops cold_walk_ops = { }; static void madvise_cold_page_range(struct mmu_gather *tlb, + struct task_struct *task, struct vm_area_struct *vma, unsigned long addr, unsigned long end) { struct madvise_walk_private walk_private = { .pageout = false, .tlb = tlb, + .task = task, }; tlb_start_vma(tlb, vma); @@ -484,7 +490,8 @@ static void madvise_cold_page_range(struct mmu_gather *tlb, tlb_end_vma(tlb, vma); } -static long madvise_cold(struct vm_area_struct *vma, +static long madvise_cold(struct task_struct *task, + struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start_addr, unsigned long end_addr) { @@ -497,19 +504,21 @@ static long madvise_cold(struct vm_area_struct *vma, lru_add_drain(); tlb_gather_mmu(&tlb, mm, start_addr, end_addr); - madvise_cold_page_range(&tlb, vma, start_addr, end_addr); + madvise_cold_page_range(&tlb, task, vma, start_addr, end_addr); tlb_finish_mmu(&tlb, start_addr, end_addr); return 0; } static void madvise_pageout_page_range(struct mmu_gather *tlb, + struct task_struct *task, struct vm_area_struct *vma, unsigned long addr, unsigned long end) { struct madvise_walk_private walk_private = { .pageout = true, .tlb = tlb, + .task = task, }; tlb_start_vma(tlb, vma); @@ -533,7 +542,8 @@ static inline bool can_do_pageout(struct vm_area_struct *vma) inode_permission(file_inode(vma->vm_file), MAY_WRITE) == 0; } -static long madvise_pageout(struct vm_area_struct *vma, +static long madvise_pageout(struct task_struct *task, + struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start_addr, unsigned long end_addr) { @@ -549,7 +559,7 @@ static long madvise_pageout(struct vm_area_struct *vma, lru_add_drain(); tlb_gather_mmu(&tlb, mm, start_addr, end_addr); - madvise_pageout_page_range(&tlb, vma, start_addr, end_addr); + madvise_pageout_page_range(&tlb, task, vma, start_addr, end_addr); tlb_finish_mmu(&tlb, start_addr, end_addr); return 0; @@ -927,7 +937,8 @@ static int madvise_inject_error(int behavior, #endif static long -madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, +madvise_vma(struct task_struct *task, struct vm_area_struct *vma, + struct vm_area_struct **prev, unsigned long start, unsigned long end, int behavior) { switch (behavior) { @@ -936,9 +947,9 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, case MADV_WILLNEED: return madvise_willneed(vma, prev, start, end); case MADV_COLD: - return madvise_cold(vma, prev, start, end); + return madvise_cold(task, vma, prev, start, end); case MADV_PAGEOUT: - return madvise_pageout(vma, prev, start, end); + return madvise_pageout(task, vma, prev, start, end); case MADV_FREE: case MADV_DONTNEED: return madvise_dontneed_free(vma, prev, start, end, behavior); @@ -1143,7 +1154,7 @@ int do_madvise(struct task_struct *task, unsigned long start, tmp = end; /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */ - error = madvise_vma(vma, &prev, start, tmp, behavior); + error = madvise_vma(task, vma, &prev, start, tmp, behavior); if (error) goto out; start = tmp;