Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp144422ybz; Tue, 21 Apr 2020 17:16:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLTmbinZ9UCTpEXugMEJuetRfeHba50RQ18lIlMcF9vwiqbC59I+74Bf6CHT70GpwOckg1a X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr23897288ejw.211.1587514564373; Tue, 21 Apr 2020 17:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587514564; cv=none; d=google.com; s=arc-20160816; b=jCE1mRjZOVDi15rVrCSLo+4WyWy3hbqlveJMVxdsIXBB8vf7//1UmqL+7wW1qXqfF4 bD1b2VWcU4xaV0hExEl9W7uF4H6d5kEoIVMjNl0DLADsraELtD5s8AVp6naHnhTRJ5NJ Yej2pK4fZg7fGf5EiO18R8fJxyo+q+oMtaE1PBpfLpFfAkGGi6MJpPLWdaMms8b9vf9q UKtZZBEE22dZ4ArF4XFD02CrLvqL0ViO2zPbO582dxsziw0UKxbpjdRybZPss8naECnd uzUviH/Jsq290Q0SrQXmGcLZ7f8R+VeioqEonJjAZhvXlEeA/WkMJRnBOfBAzXmmpVFW QfoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=nj5jjGLg8IOvfnegjPnvO+hyr9F+Q3RFMzb65ktIqNg=; b=ZmNTK/g1lpo/hlK2O8+v8JfRtVqZ1qK9Mryblar7egk0T+5jepwZPpxKBAoR6VN8Zv nBvgDBdPbYQpG6fmoxb81VSv2p5viMnZfp7xrpMZ3ToCCc4RZYIFyMQP4HXd0+bOB41a hOXHFsAZ7/0iSjgkxoKDnMKxplSX5+1OtaFdXydBHmSjuJtJK3XgZhGackHI4m1m6Ao4 kjyVIuCQd0FI5miADxeNamUgwMKJ/n+lAFEMU/gL+0noEfzVe1Khsj3ANndDsMoVIiJu liwm2RfWkvL7YtVzjpkjXfZPAf54GzbKK2GPmVZc07aZGhKOPyz1G0T+sbSQXEeiJApm dN7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="fmE/ZsCi"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yc9si2739192ejb.319.2020.04.21.17.15.32; Tue, 21 Apr 2020 17:16:04 -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=@google.com header.s=20161025 header.b="fmE/ZsCi"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726355AbgDVAO3 (ORCPT + 99 others); Tue, 21 Apr 2020 20:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726012AbgDVAO3 (ORCPT ); Tue, 21 Apr 2020 20:14:29 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8F9C0610D5 for ; Tue, 21 Apr 2020 17:14:27 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id e18so530559pfl.17 for ; Tue, 21 Apr 2020 17:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nj5jjGLg8IOvfnegjPnvO+hyr9F+Q3RFMzb65ktIqNg=; b=fmE/ZsCi12txej32MKxq5Q/M7SA+tr6q8bMHrxgAjcjNoXH82uOrxQ9hl0ksM/ez4f NPLpdNrNChzGenZ8mx71A3vcq8jSr23SjXXSs5JSrE1GiF3Gsd6gEiJ2zvEY29rNj2ac xIllsk8xqc1Z6k8VjXIaMEhazT8cisE6MUOlrpJfwmVX+L6xMjPj9HolikYBgotuYvcW r0Xde8JijOIxT99M4Wus0Ohme4Xh2bv5zz0NuyF5tAK8i+s1Pn1Dh7mc5uPWIz7CSOik LwX9Fi9+pGvkXqovzI6v/aNLkyYs+BMwHT6PMjF03zESDlDCfQEAZ1wd/Mm8hiPnuzBI q6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nj5jjGLg8IOvfnegjPnvO+hyr9F+Q3RFMzb65ktIqNg=; b=qD/0UEZJqe1JdslfzKMOU6n9rbk1yKi1nSINdA6z6IHm83U0elwV76VOVE6KBFE98O WwA5CRigIEZRcghzyNeliFxxr2iDbtMnHogBQT+d+BFiuGncx2SQZSLJGWVKHtvRZWKF fzWxuAUxcdYBz9TY6vEbbwlfgspXf7xXPG3pCOGIJkexqIU+oFXlW5pf/g7KHCDEuVrM PJYTjSlmdFZ22/ggr3IdDY68C5lrLCOyfsmQu2k7gapC/yjNXQ6lF11Ff8gI293WX4wl KWBM6ZBi1nfNBFO+cSfrRRHrfOTEZ8XCyLxrQIvFlcZLYjz4j/ipDBVFFBsp2qmusDE0 TIhQ== X-Gm-Message-State: AGi0PuZFbbtzWQU5yq+fKY6MJYhBMWpRDY5VviXooc7E5nUBuWh5E9AE wJFTC2KO39w10gktf54+7/T2tQahmlw= X-Received: by 2002:a17:90a:276a:: with SMTP id o97mr8625466pje.194.1587514467186; Tue, 21 Apr 2020 17:14:27 -0700 (PDT) Date: Tue, 21 Apr 2020 17:14:13 -0700 In-Reply-To: <20200422001422.232330-1-walken@google.com> Message-Id: <20200422001422.232330-2-walken@google.com> Mime-Version: 1.0 References: <20200422001422.232330-1-walken@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v5 01/10] mmap locking API: initial implementation as rwsem wrappers From: Michel Lespinasse To: Andrew Morton , linux-mm Cc: LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Daniel Jordan , Michel Lespinasse , Davidlohr Bueso Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change wraps the existing mmap_sem related rwsem calls into a new mmap locking API. There are two justifications for the new API: - At first, it provides an easy hooking point to instrument mmap_sem locking latencies independently of any other rwsems. - In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks. Signed-off-by: Michel Lespinasse Reviewed-by: Daniel Jordan Reviewed-by: Davidlohr Bueso --- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/linux/mmap_lock.h diff --git a/include/linux/mm.h b/include/linux/mm.h index 5a323422d783..051ec782bdbb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h new file mode 100644 index 000000000000..97ac53b66052 --- /dev/null +++ b/include/linux/mmap_lock.h @@ -0,0 +1,54 @@ +#ifndef _LINUX_MMAP_LOCK_H +#define _LINUX_MMAP_LOCK_H + +static inline void mmap_init_lock(struct mm_struct *mm) +{ + init_rwsem(&mm->mmap_sem); +} + +static inline void mmap_write_lock(struct mm_struct *mm) +{ + down_write(&mm->mmap_sem); +} + +static inline int mmap_write_lock_killable(struct mm_struct *mm) +{ + return down_write_killable(&mm->mmap_sem); +} + +static inline bool mmap_write_trylock(struct mm_struct *mm) +{ + return down_write_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_write_unlock(struct mm_struct *mm) +{ + up_write(&mm->mmap_sem); +} + +static inline void mmap_write_downgrade(struct mm_struct *mm) +{ + downgrade_write(&mm->mmap_sem); +} + +static inline void mmap_read_lock(struct mm_struct *mm) +{ + down_read(&mm->mmap_sem); +} + +static inline int mmap_read_lock_killable(struct mm_struct *mm) +{ + return down_read_killable(&mm->mmap_sem); +} + +static inline bool mmap_read_trylock(struct mm_struct *mm) +{ + return down_read_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_read_unlock(struct mm_struct *mm) +{ + up_read(&mm->mmap_sem); +} + +#endif /* _LINUX_MMAP_LOCK_H */ -- 2.26.1.301.g55bc3eb7cb9-goog