From patchwork Wed Feb 12 22:16:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11379237 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 1A8FB921 for ; Wed, 12 Feb 2020 22:16:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1B1C21734 for ; Wed, 12 Feb 2020 22:16:24 +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="m2+iclFG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1B1C21734 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 E3B2D6B049A; Wed, 12 Feb 2020 17:16:23 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DEBC56B049B; Wed, 12 Feb 2020 17:16:23 -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 D01946B049C; Wed, 12 Feb 2020 17:16:23 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id B69376B049A for ; Wed, 12 Feb 2020 17:16:23 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 55F6E181AC9CC for ; Wed, 12 Feb 2020 22:16:23 +0000 (UTC) X-FDA: 76482884646.20.grade58_71f052435e926 X-Spam-Summary: 2,0,0,18a0cf002bfd1477,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:jack@suse.cz:willy@infradead.org:josef@toxicpanda.com:hannes@cmpxchg.org:minchan@kernel.org:snazy@gmx.de,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3874:4250:4321:5007:6261:6653:7576:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13069:13161:13221:13229:13311:13357:13894:14096:14181:14384:14394:14721:21080:21444:21451:21627:21966:21990:30054:30090,0,RBL:209.85.210.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,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: grade58_71f052435e926 X-Filterd-Recvd-Size: 4382 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 22:16:22 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id i6so1934619pfc.1 for ; Wed, 12 Feb 2020 14:16:22 -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:mime-version :content-transfer-encoding; bh=IRbfdGWqcwmnNp2DnvQOXpGpDdlJdzZpC1N7ZpXf7R4=; b=m2+iclFGS8CzBhvrLeUiObRXq+BHsUSMMB7Vj20hZbpVGnjh/++VyGUTYt2woRJvbz L/tFb9D7IjjcHYxbU1p16n0jDAd49fMG5fydr961+y1BEXCfEkYgb+tn1HlwvBfA7Bk6 I9/cVK87OWQEVxTu8l4ZyYDMQ3fRJlGRnfAe3+Uf2t0Ncu/tzwbO7i0xk8enb/Cjcv1w YZOPvQVFwN9Joc3PLsZNieDH1S0lhbebYGRgZGijwZTApsCTAiSfFZDmWBpfV/IwAcQj AFrnPWicOYux0+P25+pC2SJAJIkuHnqMOCaXq8aQ1oa0O+S29vcTAOFJYlxuEeemPoyc /RsA== 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 :mime-version:content-transfer-encoding; bh=IRbfdGWqcwmnNp2DnvQOXpGpDdlJdzZpC1N7ZpXf7R4=; b=UCJQaMGeD55Pcr6OFoFwW6JiMq91leTnf5nSUvZMu6L/rQszwStrsCQIgnAxac+DvE HldvRzqm9307yaz0R/2EA2fqr5gHl11xW6kWZbvLSmyWgEzT5fJ++vi9gYyuMBTQGOlB 2FbgnGZ2otWkS+mVypQgxRPi+0e47/EJPlGsREqwDNBevg4zfCzf7uz+jC2wf/6dx11x PBR9BuswFw/OLWblTeiRU6P5sVyHDLuCzjxjn3Dtax51yXjZRkY6n1k2qs0lNZa1hCRQ XtxTYA7w6RXkBptbiCItDTH1KIHXzg7Xkmu+0JHZYbnnr4kdkwHGSONfw/4gOJpjWhq4 qe1w== X-Gm-Message-State: APjAAAXhPPmRXPpKm+uHfkxrMIRs02KuKsd2jkrkE8KV/VAyG0+6hUAv AudBDr64kQL/LSzmxZnFN8s= X-Google-Smtp-Source: APXvYqzIIedGxf8nZB9JoeCmITqMhnSUr9gnQJ8hlq9gR2gywKw1M3NDG//Z/TKJd6Spy2jGjOp+xw== X-Received: by 2002:aa7:9808:: with SMTP id e8mr14135402pfl.32.1581545781691; Wed, 12 Feb 2020 14:16:21 -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 o10sm117683pgq.68.2020.02.12.14.16.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 14:16:20 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , Jan Kara , Matthew Wilcox , Josef Bacik , Johannes Weiner , Minchan Kim , Robert Stupp Subject: [PATCH 1/3] mm: Don't bother dropping mmap_sem for zero size readahead Date: Wed, 12 Feb 2020 14:16:12 -0800 Message-Id: <20200212221614.215302-1-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog 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: From: Jan Kara When handling a page fault, we drop mmap_sem to start async readahead so that we don't block on IO submission with mmap_sem held. However there's no point to drop mmap_sem in case readahead is disabled. Handle that case to avoid pointless dropping of mmap_sem and retrying the fault. This was actually reported to block mlockall(MCL_CURRENT) indefinitely. Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations") Reported-by: Minchan Kim Reported-by: Robert Stupp Reviewed-by: Minchan Kim Reviewed-by: Josef Bacik Signed-off-by: Jan Kara Signed-off-by: Minchan Kim --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 1784478270e1..5bffaa2176cd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2416,7 +2416,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, pgoff_t offset = vmf->pgoff; /* If we don't want any read-ahead, don't bother */ - if (vmf->vma->vm_flags & VM_RAND_READ) + if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages) return fpin; if (ra->mmap_miss > 0) ra->mmap_miss--; From patchwork Wed Feb 12 22:16:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11379239 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 A550E921 for ; Wed, 12 Feb 2020 22:16:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 71C3E21569 for ; Wed, 12 Feb 2020 22:16:27 +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="m6bE/7Rq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71C3E21569 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 BCBB86B049B; Wed, 12 Feb 2020 17:16:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B7C696B049C; Wed, 12 Feb 2020 17:16:25 -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 A1BFD6B049D; Wed, 12 Feb 2020 17:16:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8A2466B049B for ; Wed, 12 Feb 2020 17:16:25 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3FD062C0D for ; Wed, 12 Feb 2020 22:16:25 +0000 (UTC) X-FDA: 76482884730.04.glue56_722c96850d73b X-Spam-Summary: 2,0,0,b39c5d59ec0b6c02,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:jack@suse.cz:willy@infradead.org:josef@toxicpanda.com:hannes@cmpxchg.org:minchan@kernel.org:snazy@gmx.de,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2898:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3874:4605:5007:6261:6653:7903:9121:10004:11026:11473:11658:11914:12043:12295:12296:12297:12438:12517:12519:12555:12895:13894:14096:14181:14394:14721:21080:21324:21444:21451:21627:21987:21990:30054:30070:30090,0,RBL:209.85.215.193:@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,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: glue56_722c96850d73b X-Filterd-Recvd-Size: 5318 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 22:16:24 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id z12so1944873pgl.4 for ; Wed, 12 Feb 2020 14:16:24 -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=qaiwdcinbwslO7EdATKJ134QGtzda46/f8mdpO086dY=; b=m6bE/7RqwfLpD1mq61rTzvjRR2ys5Ij1JFM0A0GKtF9HVX0WWCVA77x9kY/KpJrTfU JJSLpjs4+AlmTmCyUIciT3fcM6GnLxXwmzhl7i5raq1xxhDq2f93RnnIqEalWPJlEdwh JIhk6W9WGGsPQrafEVVXH+BhMV99HudisqiAGi0cyG/JwY3bw2cLmzjOK1hH6XJkuSrE YcKEbSinpUKN1NKpgYVsCo3VYMH33kH78gCd/DXZk+cVBUTCGpE6cnYRYOEvElvjvWbo 1L9lzfXy4ziL6/Y5k5HXPBcOSqL9FUEBkqFcpzqevigihsGkJimKiYplosv8jbHFaR4e e0/Q== 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=qaiwdcinbwslO7EdATKJ134QGtzda46/f8mdpO086dY=; b=MIFuRUnX35yOfoQQzWb6qzLfknV6qEsn4eToGbX7V1pN8uGoZ8VoFs0BFgWyRLx7Fv EQokW67szM5T38WR/rgbNr4EgOLXIXBCYDE0pvqe0jemlqHK1ARgsnZTF2geqhVV5GpJ anF2varse0SaKH+JF5krIFVIZU59eUZ4b88B7KASWyNkLctme8bfFLFHqA9ng+wNGfHK ULHSqOSEBT2Cp+/9vI9h+9wVmmd78FyNT3d8z9hMAjOP91ajOgUlVn+avxygKSH09ID2 eYMyZ8smUomywuAH66ioXQYphdEuogDSopbNe7GrlOsCaRNy1yCtb5vo8WNN7BfNXWn5 nbDw== X-Gm-Message-State: APjAAAVsEUldT89hfWZjc0Xwh5cJZosv0tqwzDyZS7RvWEv0bIa8zzeK jf+DlAtQCmur67psCpzzUZc= X-Google-Smtp-Source: APXvYqxEdmfgRh8AIV8cmXo8MbUCE3MelnAT6e18QMejlP/S1J+YS648UCx0O+NpBLpkC87Z+qw4Wg== X-Received: by 2002:a63:c30e:: with SMTP id c14mr15447571pgd.168.1581545783496; Wed, 12 Feb 2020 14:16:23 -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 o10sm117683pgq.68.2020.02.12.14.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 14:16:22 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , Jan Kara , Matthew Wilcox , Josef Bacik , Johannes Weiner , Minchan Kim , Robert Stupp Subject: [PATCH 2/3] mm: fix long time stall from mm_populate Date: Wed, 12 Feb 2020 14:16:13 -0800 Message-Id: <20200212221614.215302-2-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog In-Reply-To: <20200212221614.215302-1-minchan@kernel.org> References: <20200212221614.215302-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: Basically, fault handler releases mmap_sem before requesting readahead and then it is supposed to retry lookup the page from page cache with FAULT_FLAG_TRIED so that it avoids the live lock of infinite retry. However, what happens if the fault handler find a page from page cache and the page has readahead marker but are waiting under writeback? Plus one more condition, it happens under mm_populate which repeats faulting unless it encounters error. So let's assemble conditions below. __mm_populate for (...) get_user_pages(faluty_address) handle_mm_fault filemap_fault find a page form page(PG_uptodate|PG_readahead|PG_writeback) it will return VM_FAULT_RETRY continue with faulty_address IOW, it will repeat fault retry logic until the page will be written back in the long run. It makes big spike latency of several seconds. This patch solves the issue by turning off fault retry logic in second trial. Reviewed-by: Jan Kara Signed-off-by: Minchan Kim --- mm/gup.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 1b521e0ac1de..b3f825092abf 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1196,6 +1196,7 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) struct vm_area_struct *vma = NULL; int locked = 0; long ret = 0; + bool tried = false; end = start + len; @@ -1226,14 +1227,18 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) * double checks the vma flags, so that it won't mlock pages * if the vma was already munlocked. */ - ret = populate_vma_page_range(vma, nstart, nend, &locked); + ret = populate_vma_page_range(vma, nstart, nend, + tried ? NULL : &locked); if (ret < 0) { if (ignore_errors) { ret = 0; continue; /* continue at next VMA */ } break; - } + } else if (ret == 0) + tried = true; + else + tried = false; nend = nstart + ret * PAGE_SIZE; ret = 0; } From patchwork Wed Feb 12 22:16:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11379241 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 E1861921 for ; Wed, 12 Feb 2020 22:16:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD0AB2082F for ; Wed, 12 Feb 2020 22:16:29 +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="RgghztW9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD0AB2082F 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 EB3066B049C; Wed, 12 Feb 2020 17:16:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E3BE56B049D; Wed, 12 Feb 2020 17:16:27 -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 C67ED6B049E; Wed, 12 Feb 2020 17:16:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id AA8B16B049C for ; Wed, 12 Feb 2020 17:16:27 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 574C7180AD807 for ; Wed, 12 Feb 2020 22:16:27 +0000 (UTC) X-FDA: 76482884814.13.bomb76_727faae329b46 X-Spam-Summary: 2,0,0,d9a39229374e1586,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:jack@suse.cz:willy@infradead.org:josef@toxicpanda.com:hannes@cmpxchg.org:minchan@kernel.org:snazy@gmx.de,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:4605:5007:6261:6653:7903:8957:9592:10004:10226:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12895:13894:14096:14181:14394:14721:21080:21433:21444:21451:21627:21990:30012:30054:30070:30090,0,RBL:209.85.210.193:@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,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: bomb76_727faae329b46 X-Filterd-Recvd-Size: 5598 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 22:16:26 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id i6so1934721pfc.1 for ; Wed, 12 Feb 2020 14:16:26 -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=D/5iSeGXxDP+lyJUNU19NRvUdswxslkbz5wrgabobm4=; b=RgghztW93FIsObaDVTciRjZtfHpXEir8OzbNJN4SLfBEcm0ZxYvARrdoRfoXg+LwMe jwiPMshiVt5Onf2q1iAfqMGoHt/WNe9/ARKxkJHYkx8V4VZQ/dzVrs3R+y43UPMVH6Gd rkB8L7CTQkylxONFx0N68n5Yt4bLQPcZj9G0Dg2dw1d9ksO8J5Gha2Ci5J2LEMK30HQO AzHycbYzANEqFI7IuT4k4eUWczU6MiwGLtqSos2qS+eaEfioQMTKAXhXKWFO4ifupbG3 E6/7183vg2hJ+yeMpUJh+q9TdtbUJbf+s9+wi9ObLW3GaWrcAfrc9g/LKACZVKX6dNzH g0kw== 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=D/5iSeGXxDP+lyJUNU19NRvUdswxslkbz5wrgabobm4=; b=cMZ+Dvzha70qF8JHdFRqS9O/u8Y7mQHhz0/0Cx7hTppLZv30JoIr1QA/U+8V7Enb/0 1Qt1vkb1uIa3iQVXLICWd6SUu8x00OdrEMUxhH5nWIc4LzXbGy+D705TEltNHBVxuA8y 04YEHT5gN5AvraasIg14YCVyFJySHFigbdIq0StLHTPWc/6Cddz4+8wGd4NiJmmq9kHu 59T4ey+bq940MrMNIaPpCannyghL79mr48p8emXLrK4h3ez/ZWSPzW+PryDTJlQugOmH Zb7UpOON6AdkCwvVjAahL5tVCG8wT2syrVrx9rEZDmmqVjAdAHRIPUiN9CpSM4iEeN/p lSKg== X-Gm-Message-State: APjAAAUd2WbK9HvJ1rdifvzUR5EdQ6S4HM0TkOscYpfQb+4tw0ZT80x0 iE9yh/Suw+lol/YRSuzfwuU= X-Google-Smtp-Source: APXvYqz1nem2XDQSzeUCQA8Znbwsf82xp456uPoXIqYlQNqSSDiN2zIXgfgWRsDJA3ckF8qu9qTo7w== X-Received: by 2002:a63:42c4:: with SMTP id p187mr14713432pga.57.1581545785766; Wed, 12 Feb 2020 14:16:25 -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 o10sm117683pgq.68.2020.02.12.14.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 14:16:24 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , Jan Kara , Matthew Wilcox , Josef Bacik , Johannes Weiner , Minchan Kim , Robert Stupp Subject: [PATCH 3/3] mm: make PageReadahead more strict Date: Wed, 12 Feb 2020 14:16:14 -0800 Message-Id: <20200212221614.215302-3-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog In-Reply-To: <20200212221614.215302-1-minchan@kernel.org> References: <20200212221614.215302-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: PG_readahead flag is shared with PG_reclaim but PG_reclaim is only used in write context while PG_readahead is used for read context. To make it clear, let's introduce PageReadahead wrapper with !PageWriteback so it could make code clear and we could drop PageWriteback check in page_cache_async_readahead, which removes pointless dropping mmap_sem. Signed-off-by: Minchan Kim --- include/linux/page-flags.h | 28 ++++++++++++++++++++++++++-- mm/readahead.c | 6 ------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 1bf83c8fcaa7..f91a9b2a49bd 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -363,8 +363,32 @@ PAGEFLAG(MappedToDisk, mappedtodisk, PF_NO_TAIL) /* PG_readahead is only used for reads; PG_reclaim is only for writes */ PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL) TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL) -PAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND) - TESTCLEARFLAG(Readahead, reclaim, PF_NO_COMPOUND) + +SETPAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND) +CLEARPAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND) + +/* + * Since PG_readahead is shared with PG_reclaim of the page flags, + * PageReadahead should double check whether it's readahead marker + * or PG_reclaim. It could be done by PageWriteback check because + * PG_reclaim is always with PG_writeback. + */ +static inline int PageReadahead(struct page *page) +{ + VM_BUG_ON_PGFLAGS(PageCompound(page), page); + + return (page->flags & (1UL << PG_reclaim | 1UL << PG_writeback)) == + (1UL << PG_reclaim); +} + +/* Clear PG_readahead only if it's PG_readahead, not PG_reclaim */ +static inline int TestClearPageReadahead(struct page *page) +{ + VM_BUG_ON_PGFLAGS(PageCompound(page), page); + + return !PageWriteback(page) || + test_and_clear_bit(PG_reclaim, &page->flags); +} #ifdef CONFIG_HIGHMEM /* diff --git a/mm/readahead.c b/mm/readahead.c index 2fe72cd29b47..85b15e5a1d7b 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -553,12 +553,6 @@ page_cache_async_readahead(struct address_space *mapping, if (!ra->ra_pages) return; - /* - * Same bit is used for PG_readahead and PG_reclaim. - */ - if (PageWriteback(page)) - return; - ClearPageReadahead(page); /*