From patchwork Wed Feb 19 01:44:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11390193 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 12AED1395 for ; Wed, 19 Feb 2020 01:44:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C677E24654 for ; Wed, 19 Feb 2020 01:44:47 +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="AL4pzbix" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C677E24654 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 E91F36B0008; Tue, 18 Feb 2020 20:44:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E696F6B000A; Tue, 18 Feb 2020 20:44:44 -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 D321B6B000C; Tue, 18 Feb 2020 20:44:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id B78346B0008 for ; Tue, 18 Feb 2020 20:44:44 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5B3D5824805A for ; Wed, 19 Feb 2020 01:44:44 +0000 (UTC) X-FDA: 76505182488.01.sail58_638205be81611 X-Spam-Summary: 2,0,0,763c4f73eed14574,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:sj38.park@gmail.com:alexander.h.duyck@linux.intel.com:jannh@google.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:4321:4385:5007:6119:6261:6642:6653:6742:7903:10004:11026:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12895:12986:13868:13894:14096:14181:14394:14721:21080:21444:21451:21627:21990:30054:30070,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5, 0.5,Netc X-HE-Tag: sail58_638205be81611 X-Filterd-Recvd-Size: 7960 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 01:44:43 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id a6so8868293plm.3 for ; Tue, 18 Feb 2020 17:44:43 -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=c3jgjNejCBb9X6M77zvWpmzx347WGq75tEtMqAj/+Ok=; b=AL4pzbixVHKxDcp2U71m+QJepOHq30WmQqf7j+F+x7wQi2XW7iI96LNeCD/OaKmSF+ Kve/u7Jsgl64NPcQA1Q4Qoh9LhX2XTblwdrSs5djpew5yaRJI1bFsKtlOWuCFnwUaFC7 PUBYTat0BVIXGik0ytrSqhntDQW2DMum1kRT7n1JY+RN2WKKabSbQTNwJ9tJTg0u7bs9 UF0+ceWRbv4U/sfMLJ7xIMf+LxzCPc+1fjNzY6GEciumm3pfJfHaxZjMFYlp/HP07Cr5 Vd6Qi3/S+dHt1BorH7jfFvA6ii9OFJFR602lgfgvGUtoLmQFZ8eEFKp4dsmsTjBeAFnc 1gfg== 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=c3jgjNejCBb9X6M77zvWpmzx347WGq75tEtMqAj/+Ok=; b=VFk8dp7RsSog5BsyCcVepRrcpCfOuS8IkC7NaRHRdCjFVugXrT48SYbqTled0x7zO9 +HDC/iP/lTF740Tmi7+bes1BYbsUMUjqjxUJnGjj52sj++Yw6B9WHJlaQRZROfVF9BSt toJbqV3c5pWiFDaUy667NO5xXr+TbtfDcey+/Q0FB9SL/A7pbHlXwp70ReGiZZlTspIV vMj9BBfT+qCeJzZC4UJlzqEa++oYZMXxeZLiHP7zKeuDk3d6eGS00qEnBNXd4ioYUmbs fkQOWiZg4aDdO1/qRkg+0DBX48JGs0IzV4sFqbQvuzd1zlpa38tdHxy/DZgfqLkcDT2A tT1Q== X-Gm-Message-State: APjAAAVgWqRu5YCWaFfpgjDUrK89qEhIfJVGCGv7X1z+2modnthO7u1c gaBsPF00MLOxWRKNpQ2nz0o= X-Google-Smtp-Source: APXvYqygDJwDS7PyVA1yTqfgxMw2cPIblIFGAm8JUg/EszRSRLPi2m3lE8zcfv8RlWVvwMYMaTWAbQ== X-Received: by 2002:a17:902:7687:: with SMTP id m7mr23358861pll.136.1582076682761; Tue, 18 Feb 2020 17:44:42 -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 t186sm221192pgd.26.2020.02.18.17.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 17:44:41 -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 , sj38.park@gmail.com, alexander.h.duyck@linux.intel.com, Jann Horn , Minchan Kim Subject: [PATCH v6 3/7] mm: check fatal signal pending of target process Date: Tue, 18 Feb 2020 17:44:29 -0800 Message-Id: <20200219014433.88424-4-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200219014433.88424-1-minchan@kernel.org> References: <20200219014433.88424-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 has pending fatal signal during (MADV_COLD|MADV_PAGEOUT) operation. Signed-off-by: Minchan Kim Reviewed-by: Suren Baghdasaryan --- mm/madvise.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index f29155b8185d..def1507c2030 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 *target_task; }; /* @@ -316,6 +317,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (fatal_signal_pending(current)) return -EINTR; + if (private->target_task && + fatal_signal_pending(private->target_task)) + return -EINTR; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (pmd_trans_huge(*pmd)) { pmd_t orig_pmd; @@ -471,12 +476,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, + .target_task = task, }; tlb_start_vma(tlb, vma); @@ -484,7 +491,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 +505,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, + .target_task = task, }; tlb_start_vma(tlb, vma); @@ -533,7 +543,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 +560,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; @@ -929,7 +940,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) { @@ -938,9 +950,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); @@ -1140,7 +1152,8 @@ int do_madvise(struct task_struct *target_task, struct mm_struct *mm, tmp = end; /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */ - error = madvise_vma(vma, &prev, start, tmp, behavior); + error = madvise_vma(target_task, vma, &prev, + start, tmp, behavior); if (error) goto out; start = tmp;