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); /*