From patchwork Mon Mar 2 19:36:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11416205 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 0F4DF14B4 for ; Mon, 2 Mar 2020 19:36:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C68BF24676 for ; Mon, 2 Mar 2020 19:36:50 +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="PAzwG+yh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C68BF24676 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 EF67B6B0007; Mon, 2 Mar 2020 14:36:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E80A26B0008; Mon, 2 Mar 2020 14:36:47 -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 CFBD36B000C; Mon, 2 Mar 2020 14:36:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id B6F676B0007 for ; Mon, 2 Mar 2020 14:36:47 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 837CB8248068 for ; Mon, 2 Mar 2020 19:36:47 +0000 (UTC) X-FDA: 76551429654.04.shoe32_7573e3f5e4862 X-Spam-Summary: 2,0,0,a0bce866f2eed190,d41d8cd98f00b204,minchan.kim@gmail.com,,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:4119:4250:4321:4385:5007:6119:6261:6642:6653:6742:7903:10004:11026:11658:11914:12043:12291: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.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: shoe32_7573e3f5e4862 X-Filterd-Recvd-Size: 8008 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Mon, 2 Mar 2020 19:36:46 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id p7so191142pli.5 for ; Mon, 02 Mar 2020 11:36:46 -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=s2zELO0pXNHVNnEg0MBIPznZHBtLOycXK0nlVtImdKo=; b=PAzwG+yhEbaBhr9u+SnVfypO8PjkR7/DXaWSeTqBeJJDqlGyx4HdAjzmvBYKvWjTyM 62APTEt8o7mpnHqGpm5hQRK73twpZHbU6te9ZtekGqY/K6cFYoW+91EEsObzhFLEewvA 94H/BotmZyp5Wvfe1TG6y/SsNb2eeRbTlbTuoVOrASVtzsPPiZ7G0arlCirm0Fmlvd08 PR6goKzXlelvQjgxe0Xl6avWaqL72hY6n6D7q3t6VhKB7JNZTXSrIOLK5qtEHrTEvb94 DgCCieWO2QVrMMeYMzRg1HJhUy/4jXDasVw7xvLJ9W35CKZwyHyMY13wi/VYkj4Bl+eG PRbw== 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=s2zELO0pXNHVNnEg0MBIPznZHBtLOycXK0nlVtImdKo=; b=UPfoyMxQ4vFM3FPrtoG+l9ep5CpI0vbi25fe9qvkLQXodoz3q1T8bPxllzgOxreqeC 0SZ5nTWDTgaTmPg4hScAFq/nIxME6/k1RzzfSqCwOD9uMprLtXVjd7g4Z+75VkhvsaKJ Kxy0w9p6LYdDAh/h2NaCXaAEa+tmadqG7oFgAZrRYzxhQtFAjG0hArGsvXW5DftRek2A Ldlj+IBW3C0C+Yl3Hcw+rcnmOsZ8R7R9OD5x0OjWeaCfzOrVBzTBuPk73EOo7LbfoXWL ig/rB/jggUvTIJ89p5Q7lzOqwHGmMRHEcL8Hly9zQC82iorT1hBDz1694L2KZz2bD0dC N9Kw== X-Gm-Message-State: ANhLgQ1+zzHR4IU8JVHaNXNzGirr112dZzxMLfhzcpbOQ1joSSLtrK7f 4w3lrz+Bjoka9spNhrqOCqI= X-Google-Smtp-Source: ADFU+vuCN+hZoW3eWaVKy2lfwyQyeXd2iNvJdu5DasPNMIZzpt5ghLScTJBTDyNimuUZlbB+XdRxzQ== X-Received: by 2002:a17:902:9889:: with SMTP id s9mr623488plp.252.1583177805961; Mon, 02 Mar 2020 11:36:45 -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 hg6sm35441pjb.22.2020.03.02.11.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2020 11:36:44 -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 , Jann Horn , alexander.h.duyck@linux.intel.com, sj38.park@gmail.com, Minchan Kim Subject: [PATCH v7 3/7] mm: check fatal signal pending of target process Date: Mon, 2 Mar 2020 11:36:26 -0800 Message-Id: <20200302193630.68771-4-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302193630.68771-1-minchan@kernel.org> References: <20200302193630.68771-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. Reviewed-by: Suren Baghdasaryan Signed-off-by: Minchan Kim Reviewed-by: Vlastimil Babka --- mm/madvise.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 349473fc6683..6543f2bfc3d8 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;