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.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 0446DC433DF for ; Sun, 24 May 2020 19:23:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D67A620787 for ; Sun, 24 May 2020 19:23:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="2Ls3+QLC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388156AbgEXTXA (ORCPT ); Sun, 24 May 2020 15:23:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388116AbgEXTWS (ORCPT ); Sun, 24 May 2020 15:22:18 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79194C08C5C1 for ; Sun, 24 May 2020 12:22:17 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id c75so7784275pga.3 for ; Sun, 24 May 2020 12:22:17 -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=2Ls3+QLCLeno0jCON841EcWXGQKWPnDvCePQ3gzUcj9mNawaAgmwjotTCl0/7xbnda rfxeTUTHpN3qCYhSv6xAt8Ant4ZfpAttPgjaMPnqiBrqlKdjHbTCVwhoAj8/Hb970o35 6v3SO2V1GK52FaER0WaJA+/6MYb7O1/C9c2j1MWKSLceSlecvpDxRZr5wYCbQ3y3sT1F vp3sOzstbaxM5MzE8nggK0lWKSOdFNKCUjqvlIACct9959BpZmY5bBCc84O/BXO9klJw KD55lffQl2jrhCxficFT0VRaS/iOfhiJ8jApT9QjIGenWhJtjx7T0ZT6PipOddmqq97e PS3Q== 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=rFfpp5XHz8n5B5uwDm0UcnGuj5Dcdw7qk9i6qdyXfSQV7GZmCEIqw3CVj4MGP964pK d6n8KmUm5CIFCPy536bt33gsF38kS9zoapEPE6PIJ53lwbYwme2KeTzhkF9v+BRbgFrs iM+Sc9Bc3uigF0g1ew6fLIUhcJTe313N6sjggpEBbH1M8jrUvjeaW7FK+jGTJJuMcKol ZpgyEeknTxty4GfIid4XejmvD5S/s1UU4j+AG/DXD3ME7n/OV3RR5O5iRF0WsTVUTgHt 6D7pif0zE6edCPkOFHZw89BufunllK8k2UYUbNp1Y4WJ9UuDspTHx8hjvzNqtWi5WP1d K0bA== X-Gm-Message-State: AOAM533uBjSPnD8H6SEsaXKQS2GejQz2LxHXcCfOy2SpzFl0eypRQgCq aLFQIjauzbsAc1x1nfRY7FN3Stdl/7Ijmw== X-Google-Smtp-Source: ABdhPJyhydzeyBlKQCRTW6m8/JKp1oOARrRFIDQLFSR3T+UzUCwXLRBHN9D1E2V8YIjgAYJPFkMCtw== X-Received: by 2002:a63:dd0c:: with SMTP id t12mr23468725pgg.293.1590348136731; Sun, 24 May 2020 12:22:16 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:c871:e701:52fa:2107]) by smtp.gmail.com with ESMTPSA id t21sm10312426pgu.39.2020.05.24.12.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 12:22:16 -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, Jens Axboe Subject: [PATCH 03/12] mm: abstract out wake_page_match() from wake_page_function() Date: Sun, 24 May 2020 13:21:57 -0600 Message-Id: <20200524192206.4093-4-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200524192206.4093-1-axboe@kernel.dk> References: <20200524192206.4093-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@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