Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp275261ybm; Tue, 26 May 2020 16:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyehTihtMXC/P2WzBhFavkEijhpbeT/mCUc8fOG2UTxVzzKUZqMN8ccib93tToPn0bQEjBN X-Received: by 2002:a17:906:a38b:: with SMTP id k11mr3153068ejz.473.1590536592296; Tue, 26 May 2020 16:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590536592; cv=none; d=google.com; s=arc-20160816; b=z4tg6FKGgF1Kr23iDrvGXqo3cXg5A9zCPy+jagYDQPJQHh/SQ/g9kdk/+EUuD0bmPw 6LmAICmJSOR1eMNQNtw/mbVs053FipnTlwBasfIhF7fI4zv1i8NkD/FsICkebjlWGa5V gYJy1Xel3H3LoaJPbywx+XKj/3FmT28ziXJmA8G21vgMaFFBYlGIsSvnB5rwB5OFVoSR Bsqepyx4vm0LaAZvPncIidWgISUN+NeGj5Jz/I/FduLFgv3fXRKyWKds0ZusfNAiz+Ta ec7Ck4krKHUdITeCq2JBwU+aEBpjGcQSyLaUb+6lGw/dYWUmyIVC3RGmgaUpqziKBBP3 x36Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=SB4MRe9V5Sf3CrlRDwS81ZQlusfRvTq83lHtsWUeRmoCRM3d8zslOJgpGUsB89cozV gVw3IvEYzYYmO6AzgU+C9+VsrsAHWloD/YW623xVoAO7B3q057R3cJZKiOWP0/XaCMfM VSioE8aKGmucH2bBRY+lESfyFgXOeb8anK2H64iH03PX4ie1YA8EjjIxX/FlKtNsUpJ5 ZvUbI9ZZw4mQ9abR1TgYlwLyljm21NEPfweNIBAS8V0rJ6svHsstWGqkqK/AvKvZgqSW fjtZoj8B7VCBB6LW3sNgLOOHTXhuphjqwahgWMDJR4inGrzlgS9DbJewFO2SMS0OhHii Osuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YKbLOw6L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si744680eju.299.2020.05.26.16.42.49; Tue, 26 May 2020 16:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YKbLOw6L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390288AbgEZTvd (ORCPT + 99 others); Tue, 26 May 2020 15:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390179AbgEZTva (ORCPT ); Tue, 26 May 2020 15:51:30 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B03CCC03E96E for ; Tue, 26 May 2020 12:51:30 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t7so9113669plr.0 for ; Tue, 26 May 2020 12:51:30 -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 :mime-version:content-transfer-encoding; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=YKbLOw6LpYloCfEz6cSjXDp7lo/SEH14850NuBSfnHJZqbSNda9ft1KrD9kDTlgX29 i5p9OTzKmGtxOrMHS+JBQto/yzM9zXGeRvk09gakJOY0/1BHuWAqj05obqvWTcQqZXjM tSs3FQLGux7Ieod96lB3tb6zv/Ei+e+rH+jvFEsgFfzk6f2Q6xviMQedqciMUxeS5bww YudmGt61FcA28hKFe3zbgPJZzUu27iwTT39ESm3iUzvAQWSmULv85wglM46pdLh9xw2G 2vQ4GSnPWkUwbN9Hsml5BFWibSXp84PL/jR8cl2CQ0mI7mUEGk1xtvkYObM/1b+lAY5j 3Wiw== 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:mime-version:content-transfer-encoding; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=IzO5Fk9+/2aB6BtFGlbULPoxqpehan66fQPl8lN7Pt/SOpp/C2aNYR7HxOK/GAiEEC a2Lt0Nz7HXgI5BzwYNf9Nr4+/8wel7uEX86tFiSfBSOLl+BHLE10xKo2bCBTwfSzjbvz 3tUAXug0wzA/5H6oWPtkpL6odRak0wmnDJAil6a2TVA34igyd8xPv6IILgKoUZeT+q1z BjOkP4C6t+YWZmSwcvQiFxhhTbuu1327Atk1vDOleKzZqoB9fweuQ5YapthHYuYWDGki A12r1f1C64kDkAg1puZqendlyI5d1ND5wfaceDh1+0SkZ4TNA/1txPr+tMiJKqIDKhqg 88LQ== X-Gm-Message-State: AOAM533omJxV4k9z+NGa7VP7ZgAD7P17VCP1A9XD03lPkTVyGmvxqSz1 3WK0alPf8rsocdR+phA+L0vTGQ== X-Received: by 2002:a17:90a:f283:: with SMTP id fs3mr874913pjb.1.1590522690209; Tue, 26 May 2020 12:51:30 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:94bb:59d2:caf6:70e1]) by smtp.gmail.com with ESMTPSA id c184sm313943pfc.57.2020.05.26.12.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 12:51:29 -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 Subject: [PATCH 03/12] mm: abstract out wake_page_match() from wake_page_function() Date: Tue, 26 May 2020 13:51:14 -0600 Message-Id: <20200526195123.29053-4-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526195123.29053-1-axboe@kernel.dk> References: <20200526195123.29053-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No functional changes in this patch, just in preparation for allowing more callers. 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 a8f7bd8ea1c6..53d980f2208d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -456,6 +456,43 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma, return pgoff; } +/* 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 != key->page) + return 0; + key->page_match = 1; + + if (wait_page->bit_nr != 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 80747f1377d5..e891b5bee8fd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -990,43 +990,16 @@ void __init pagecache_init(void) page_writeback_init(); } -/* 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, int sync, void *arg) { struct wait_page_key *key = arg; struct wait_page_queue *wait_page = container_of(wait, struct wait_page_queue, wait); + int ret; - if (wait_page->page != key->page) - return 0; - key->page_match = 1; - - if (wait_page->bit_nr != 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 = wake_page_match(wait_page, key); + if (ret != 1) + return ret; return autoremove_wake_function(wait, mode, sync, key); } -- 2.26.2