From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64D94C433E3 for ; Thu, 18 Jun 2020 14:44:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27F4A20897 for ; Thu, 18 Jun 2020 14:44:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="YeULpx9I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27F4A20897 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9889F8D001E; Thu, 18 Jun 2020 10:44:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 935C08D0018; Thu, 18 Jun 2020 10:44:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84A528D001E; Thu, 18 Jun 2020 10:44:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 682A28D0018 for ; Thu, 18 Jun 2020 10:44:09 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 26E431495E1 for ; Thu, 18 Jun 2020 14:44:09 +0000 (UTC) X-FDA: 76942602618.19.feast50_3317cb626e11 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id EDCCF1AD1B2 for ; Thu, 18 Jun 2020 14:44:08 +0000 (UTC) X-HE-Tag: feast50_3317cb626e11 X-Filterd-Recvd-Size: 6414 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Thu, 18 Jun 2020 14:44:08 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id y17so2516374plb.8 for ; Thu, 18 Jun 2020 07:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=L8y2vzO4eFciFziI46a/ttSbeGYaIdwkqPPuYZk9V/Y=; b=YeULpx9IMVYlet06hXXtF3Dyovfb6OWV7znBhPslocYv61JEKGOzA86Uf7KlkwQUxA 5veTkQm0U3FiHje/G2qBCvINtR+5H6+EjnG+6Sf5DBiwhwEgiK3ZySkgoWKeRlArsl6Z KII1sM40sgw0BBBEt/0RNUdVdIscLTYaAk11C3WKb8/EKEdqvKbfubfLIO/VBQ2Xx9WL CEYBtGHqlJYku+rfQdHayepPiSv6ME4oZxtjXE8I56CTLxFCqrzXuobRRnwbzTHobf+i uKAVIMjqM417ECasSBzSLduZSGdbDtTFAHLkWJ12coSXUTQ7pSi5y5D2Y4Jzync6tV9q xrBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=L8y2vzO4eFciFziI46a/ttSbeGYaIdwkqPPuYZk9V/Y=; b=BHQKhkZrIzAe6uh93DDItATFnXgB2gs0SbVq9eDgk1ThEnJyuw+RMhBifuFHVBoUto 9Y8eKZve+atlByca69m4MhuXA6+RVFZKRHCOkBxGvURuNFEV2wcW5qoDPrJZwLThp+VU kSwH1q8MJ2OKgKCNs5GdrK2xl9/2Uz8EkYPunC4972imDhjYMNIAy6s/7cvAYzBtM9O6 hC1In8hJKgLhJqZJnlt3L2ej+UzmlzqKmIN/lZfs2898m3abvHsotmh1YXIchxvOyndm ogdvzkavlHTxOE57GMSvd1OCFZ4ettYpnA/l4xuxUOAkA7QSOrNEcViiq5nzWnMmf8cW MQWA== X-Gm-Message-State: AOAM532IyxtQT+/op3/JJzUmASDyslej5UMBtO6AXQXOd2w6etFgfQcc keS5wItKBkAb15gm9j16SRO7Ww== X-Google-Smtp-Source: ABdhPJwx9um0vmY0DnYUG9kEzc1v1xMH5bH+K7HVKhmpcv+yl+Hyx+jkxHpVYBs3czBGcr7qfQ+u8g== X-Received: by 2002:a17:902:8690:: with SMTP id g16mr4021455plo.257.1592491447688; Thu, 18 Jun 2020 07:44:07 -0700 (PDT) Received: from x1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id g9sm3127197pfm.151.2020.06.18.07.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 07:44:06 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, Jens Axboe , Johannes Weiner Subject: [PATCH 06/15] mm: abstract out wake_page_match() from wake_page_function() Date: Thu, 18 Jun 2020 08:43:46 -0600 Message-Id: <20200618144355.17324-7-axboe@kernel.dk> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200618144355.17324-1-axboe@kernel.dk> References: <20200618144355.17324-1-axboe@kernel.dk> Reply-To: "[PATCHSET v7 0/15]"@smtpin19.hostedemail.com, Add@smtpin19.hostedemail.com, support@smtpin19.hostedemail.com, for@smtpin19.hostedemail.com, async@smtpin19.hostedemail.com, buffered@smtpin19.hostedemail.com, reads@smtpin19.hostedemail.com MIME-Version: 1.0 X-Rspamd-Queue-Id: EDCCF1AD1B2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 Content-Transfer-Encoding: quoted-printable 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: No functional changes in this patch, just in preparation for allowing more callers. Acked-by: Johannes Weiner Signed-off-by: Jens Axboe --- include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++ mm/filemap.c | 35 ++++------------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index cf2468da68e9..2f18221bb5c8 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -496,6 +496,43 @@ static inline pgoff_t linear_page_index(struct vm_ar= ea_struct *vma, return pgoff; } =20 +/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c *= / +struct wait_page_key { + struct page *page; + int bit_nr; + int page_match; +}; + +struct wait_page_queue { + struct page *page; + int bit_nr; + wait_queue_entry_t wait; +}; + +static inline int wake_page_match(struct wait_page_queue *wait_page, + struct wait_page_key *key) +{ + if (wait_page->page !=3D key->page) + return 0; + key->page_match =3D 1; + + if (wait_page->bit_nr !=3D key->bit_nr) + return 0; + + /* + * Stop walking if it's locked. + * Is this safe if put_and_wait_on_page_locked() is in use? + * Yes: the waker must hold a reference to this page, and if PG_locked + * has now already been set by another task, that task must also hold + * a reference to the *same usage* of this page; so there is no need + * to walk on to wake even the put_and_wait_on_page_locked() callers. + */ + if (test_bit(key->bit_nr, &key->page->flags)) + return -1; + + return 1; +} + extern void __lock_page(struct page *page); extern int __lock_page_killable(struct page *page); extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, diff --git a/mm/filemap.c b/mm/filemap.c index 3378d4fca883..c3175dbd8fba 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -987,43 +987,16 @@ void __init pagecache_init(void) page_writeback_init(); } =20 -/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c *= / -struct wait_page_key { - struct page *page; - int bit_nr; - int page_match; -}; - -struct wait_page_queue { - struct page *page; - int bit_nr; - wait_queue_entry_t wait; -}; - static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, i= nt sync, void *arg) { struct wait_page_key *key =3D arg; struct wait_page_queue *wait_page =3D container_of(wait, struct wait_page_queue, wait); + int ret; =20 - if (wait_page->page !=3D key->page) - return 0; - key->page_match =3D 1; - - if (wait_page->bit_nr !=3D key->bit_nr) - return 0; - - /* - * Stop walking if it's locked. - * Is this safe if put_and_wait_on_page_locked() is in use? - * Yes: the waker must hold a reference to this page, and if PG_locked - * has now already been set by another task, that task must also hold - * a reference to the *same usage* of this page; so there is no need - * to walk on to wake even the put_and_wait_on_page_locked() callers. - */ - if (test_bit(key->bit_nr, &key->page->flags)) - return -1; - + ret =3D wake_page_match(wait_page, key); + if (ret !=3D 1) + return ret; return autoremove_wake_function(wait, mode, sync, key); } =20 --=20 2.27.0