From patchwork Wed Oct 16 04:35:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizhe.67@bytedance.com X-Patchwork-Id: 13837713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BC98D2069D for ; Wed, 16 Oct 2024 04:36:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05A6C6B007B; Wed, 16 Oct 2024 00:36:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00A556B0082; Wed, 16 Oct 2024 00:36:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3AE26B0083; Wed, 16 Oct 2024 00:36:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CB6576B007B for ; Wed, 16 Oct 2024 00:36:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F3A34C199C for ; Wed, 16 Oct 2024 04:36:06 +0000 (UTC) X-FDA: 82678203342.24.59AD5B8 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf08.hostedemail.com (Postfix) with ESMTP id D72AC160003 for ; Wed, 16 Oct 2024 04:36:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="KacA/har"; spf=pass (imf08.hostedemail.com: domain of lizhe.67@bytedance.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=lizhe.67@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729053328; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=vqqd6q78BxI0CU824J9cvO4t84aKbKAkVfW5iWzN9E8=; b=UT2cSn8CibcyNwEgtk/MVvJNA72xf3v2rxoyr8Mk7oMEnbcCiVRUym0o5Tba3WwYvhmAB1 yYh44BiUG6iOUKulQgBRPbP85YppWY2wgQQyP6CjGRelV215D4p5jEJp40W5XytVvH8Gj/ rtKKFa1ueFJUy/uulzVkeKYMeDvPn6k= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="KacA/har"; spf=pass (imf08.hostedemail.com: domain of lizhe.67@bytedance.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=lizhe.67@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729053328; a=rsa-sha256; cv=none; b=aUmel8hRfnK4dE5uXzXKUkJxs972NDZ/H5PeOlKRri8F9eytvAZwgQ98tyyZBTdT7+Ggyq DD9tZQimySnRsBUzYLmanLbEVbI2GywmnLYeXUlc1uQLB07t5zcX+ogoNN1/cXpS3G8s3B 5i59hYCOHmtd8oMjMFzlYYWa51J2dxo= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ea78037b7eso2960816a12.0 for ; Tue, 15 Oct 2024 21:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729053373; x=1729658173; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vqqd6q78BxI0CU824J9cvO4t84aKbKAkVfW5iWzN9E8=; b=KacA/harfQT/zGPXp0bD1Z5ZP8ADmSuVWbhhBhNp3U06jMciIX6jteF0oG/6YRhpAt T9jUKkWxK6WPiWKbIYWuPdq4L+5lv6hhpKsIP2R1sBN+elCZN04Q4GqKD1jCTT/dVvid XrLYyFxe6+XNbaxFGCspME/EoWpGejjE2GQK9Grbvjyn4eziVPiL6LERkayxUNAQDo1z bSBcgKlDvM+qo1bfHT85KMA+Of+ql1pdP1UBW5FrLs18XnYqFbs7V19SzBrPLhbKiSNW bLNbMVugNJjdUkbPFrDHEpeaVuE666FFN6ozwSVOV+vo905u3tBVN24aZJbB6ofsd1eS yAhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729053373; x=1729658173; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vqqd6q78BxI0CU824J9cvO4t84aKbKAkVfW5iWzN9E8=; b=CeYgOfDXqF0po0ZL46ZTK5XlvvSN8H3mJAp3KZCWYaHe/8pkMospsXA0HcIr0SYWnw BNZon+sG5SgvVrxeItRfArRw11f8F/+tTeHSZu301zL+fjMp3ziFQqkz4hxvEyOtx3OO 1D1EsgEqrNX+sf7wot9CVHh0FYz+R9eZmdjA2n+Kxo2AnKJ++rSzW8jLz8vPUDvLCygm T8xnw8YpgSExDxtTKxonU/FOsMM/uePT7WAMrgdLUso/a0+XCUpabBWECFCBDtnE4mKN tieoBp96lf7jg0gKROwYvTv28LAMUz+zYSRN5zc1BDIweQ0Il/KLyp3+TkFAo7YrM0/4 MmZw== X-Forwarded-Encrypted: i=1; AJvYcCWzbesNdMyFhD/mDyECH5Mvat2h9YUOwtC1ogP1nlqe1A+Y1tm5Cakz7bB3epcAoHw58PnROZxB4g==@kvack.org X-Gm-Message-State: AOJu0YyJo0k2wPs/W/E7EB4z/Bc27f3lQcOUgxULFrY96qPhUoHczlZS jfteTyV6ldz90JNIXM7Hasbm1J1MqYBGycc1kdMH49thdaRbH57/fuQruWBG3rM= X-Google-Smtp-Source: AGHT+IEK1hvescxPxPc6pwGW1b9EOHQ1bmNSkX7E0ygZg8JO5Ed7uYaLkOxbUJa2xc5HWUdiyI+Y4A== X-Received: by 2002:a05:6a20:2d2a:b0:1d8:aa64:8733 with SMTP id adf61e73a8af0-1d8bcf430edmr24601378637.26.1729053373032; Tue, 15 Oct 2024 21:36:13 -0700 (PDT) Received: from GQ6QX3JCW2.bytedance.net ([203.208.189.8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77518a76sm2189192b3a.220.2024.10.15.21.36.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 15 Oct 2024 21:36:12 -0700 (PDT) From: lizhe.67@bytedance.com To: peterz@infradead.org, mingo@redhat.com, will@kernel.org, longman@redhat.com, boqun.feng@gmail.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, lizhe.67@bytedance.com Subject: [RFC 0/2] rwsem: introduce upgrade_read interface Date: Wed, 16 Oct 2024 12:35:58 +0800 Message-ID: <20241016043600.35139-1-lizhe.67@bytedance.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: sck4nqi9xtowsuewwsp7nzga7cnni6ea X-Rspamd-Queue-Id: D72AC160003 X-Rspamd-Server: rspam11 X-HE-Tag: 1729053368-361725 X-HE-Meta: U2FsdGVkX18uLKBMANrBg3CvbCesbNIDkKvstqwJeA9cx4oL9oBThYqYTpV16EO0jgcrGbV9ea73izYmiJ0JXLkzzWrx8xVfiIUkBka702i8otU3dT8rlWzxZPzRkoqsCtFcN/+VuwYpWvIexjHKJG/1kdvJFYh2kOMvqUCrw9rLG3KbwUFuzJpPi4HQdfJSGHc7SeGCtfO5+PG8Vm3HB6EJsZKm/X+NlI5kwovHVrAL/GHSX3KljCBNk9Sf/I9yM7Ywbp/R77qIovJu80cYk++bN+2M1lkhcyM6eVIo3cEVww16SIXFtphjpcHIM97XQ2HylldB5nL9xyooN66Kqe4Ybe1lNNb3fVZ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ilter, spamicity=0.004006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Li Zhe In the current kernel rwsem implementation, there is an interface to downgrade write lock to read lock, but there is no interface to upgrade a read lock to write lock. This means that in order to acquire write lock while holding read lock, we have to release the read lock first and then acquire the write lock, which will introduce some troubles in concurrent programming. This patch set provides the 'upgrade_read' interface to solve this problem. This interface can change a read lock to a write lock. Li Zhe (2): rwsem: introduce upgrade_read interface khugepaged: use upgrade_read() to optimize collapse_huge_page include/linux/rwsem.h | 1 + kernel/locking/rwsem.c | 87 ++++++++++++++++++++++++++++++++++++++++-- mm/khugepaged.c | 36 ++++++++--------- 3 files changed, 104 insertions(+), 20 deletions(-)