From patchwork Wed Jul 18 22:58:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10533431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C618F6020A for ; Wed, 18 Jul 2018 23:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA5BE298BA for ; Wed, 18 Jul 2018 23:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACDAA298BE; Wed, 18 Jul 2018 23:00:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 626C9298BA for ; Wed, 18 Jul 2018 23:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730955AbeGRXkO (ORCPT ); Wed, 18 Jul 2018 19:40:14 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45806 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbeGRXjW (ORCPT ); Wed, 18 Jul 2018 19:39:22 -0400 Received: by mail-pl0-f65.google.com with SMTP id 94-v6so2683397ple.12 for ; Wed, 18 Jul 2018 15:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lnhh2st4VX6fehK5+kTz/Y62FrZVJOTwdJg1BYsX/0s=; b=gKKSfyFh/FCLHtCMA0kiqlE5CiijuIkzB+rU0uXmOJkm8MWdAonRtkDeAeTojl5eKV G5jChoGSvQhFrIFPthuvPZLAt944+xJ9e/0NOa6KLae4Bkb/Nu8R9xfXXJUlLadxMQUD kRXwJIF2vkxhoRn7Kv09R4V5N4bdAgZYKqKPW2Zw6Y1f4+C7krfhzg3OG9+IS/AAjA+j DLPCEJerGHgLBYC6UX0Kj8tj8F+uptRsub6+S5cLJQ73Nk7e+N2nFQdHadEABdSV/sJX m531CksYuv6BXdup7P81hbz6eGU+pgiksyJz74Q0qiFMRQ8OLkeA2pNCsF2fiJoXEx97 Ej5Q== 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; bh=lnhh2st4VX6fehK5+kTz/Y62FrZVJOTwdJg1BYsX/0s=; b=LjYjnTxreVRPgbOVt6PO4ftNQenMeW5Zx4SHjNdGTMpd8am7L8aZpRceIvzHM+h5ta SPqnAo5k6hXdMkOpFxYAl4/lRFkvFZWNvKNi8UbpYiFxxkjhBkoja3GVuCPPfKSbxA6V 80l8sZDvFvCubmzpak0ChCAfhV9m7kZGitIbeTel97+9Mpt721wTbrNO4hWoo1sdCGib nJ/4T0BmugfBRIy0oZPaN01tICelU7LQaFBK2uB5PcCx4Ay9fWCnbb56GTcGo8GZwYsF 5z7gQ6XhCgS+4UVJkkmxRZLmqF1QmXFEHj36SQ7Nn4D8nr4chPDBKNfwK0CtNR8AxdOq 0Hcw== X-Gm-Message-State: AOUpUlGF2R0n3swE1adoIePqYQrStvCkZvHrjm4b9LcFirHCbwSVgjMU 0BkQbZDAwqNogHR/g4DsPJh2SveDORU= X-Google-Smtp-Source: AAOMgpc8447Ag1hXtUydGpCL49hHJ4EVktEXb0qgfGD60nGKEio6lV+p/SKdrQrehrzV/AAq27fOVQ== X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr7562887pli.191.1531954755568; Wed, 18 Jul 2018 15:59:15 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id s16-v6sm6377946pfm.114.2018.07.18.15.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 15:59:15 -0700 (PDT) From: Omar Sandoval To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Alexey Dobriyan , Eric Biederman , James Morse , Bhupesh Sharma , kernel-team@fb.com Subject: [PATCH v3 2/8] proc/kcore: don't grab lock for memory hotplug notifier Date: Wed, 18 Jul 2018 15:58:42 -0700 Message-Id: <0a4bc89f4dbde8b5b2ea309f7b4fb6a85fe29df2.1531953780.git.osandov@fb.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval The memory hotplug notifier kcore_callback() only needs kclist_lock to prevent races with __kcore_update_ram(), but we can easily eliminate that race by using an atomic xchg() in __kcore_update_ram(). This is preparation for converting kclist_lock to an rwsem. Signed-off-by: Omar Sandoval --- fs/proc/kcore.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index b0b9a76f28d6..e83f15a4f66d 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -118,7 +118,7 @@ static void __kcore_update_ram(struct list_head *list) LIST_HEAD(garbage); write_lock(&kclist_lock); - if (kcore_need_update) { + if (xchg(&kcore_need_update, 0)) { list_for_each_entry_safe(pos, tmp, &kclist_head, list) { if (pos->type == KCORE_RAM || pos->type == KCORE_VMEMMAP) @@ -127,7 +127,6 @@ static void __kcore_update_ram(struct list_head *list) list_splice_tail(list, &kclist_head); } else list_splice(list, &garbage); - kcore_need_update = 0; proc_root_kcore->size = get_kcore_size(&nphdr, &size); write_unlock(&kclist_lock); @@ -593,9 +592,8 @@ static int __meminit kcore_callback(struct notifier_block *self, switch (action) { case MEM_ONLINE: case MEM_OFFLINE: - write_lock(&kclist_lock); kcore_need_update = 1; - write_unlock(&kclist_lock); + break; } return NOTIFY_OK; }