From patchwork Wed Jul 25 23:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10544955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E2FC112E for ; Thu, 26 Jul 2018 00:00:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E2432A9D4 for ; Thu, 26 Jul 2018 00:00:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4228B2A9D9; Thu, 26 Jul 2018 00:00:29 +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=ham 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 DDCBD2A9D4 for ; Thu, 26 Jul 2018 00:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728825AbeGZBOb (ORCPT ); Wed, 25 Jul 2018 21:14:31 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:34134 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728339AbeGZBNe (ORCPT ); Wed, 25 Jul 2018 21:13:34 -0400 Received: by mail-pl0-f67.google.com with SMTP id f6-v6so3959574plo.1 for ; Wed, 25 Jul 2018 16:59:30 -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=16w7KIxIKq7DVWU2jRPaeALdZ2xcgpzjcsj3qPwpVus=; b=H8lv7CQz9Qhs+Me4ITN+H1NBrrZKWUlWKl8IttdoHw9pbcu7/y5Y/ecyBmvtF1RU8s LRZWVUWm+88wGlAeFjQnVeasM1NBRW2bkMkPjUCxEk93S95BeyBK3o7UsNdsrhgtnKVU ykexTEW1V95SqWAhpKw3QCL+xLTMvY54AYGy8GOwfMDoljdCb9ebAiK+FEi8dudZej9K SkQj3xNoOQLOP+llb6POAjraikm3LE7+9vySjfw4OYcSk34g1QgsIv0JFHHi6BnDYjC7 q8I0aTPPnoIR8hmpjnWejZdupqx9TveBwRWWgjK8tTwzsp/gvF+16H66TVmuq9niJjGJ Oy0Q== 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=16w7KIxIKq7DVWU2jRPaeALdZ2xcgpzjcsj3qPwpVus=; b=JTnxz1bxoK14RatPu0XPBevou7hTa7pzXPqSIF6PgKL8CgTNlpqFv7pfGRdnsxEZK5 CaUAVF1mPASTWxfEHkXCZ9sZdG7M+993jbfiWglg1YnNtQvQQjRsTpSVfdB6AFQQoBFm vviEpyfLkIEHfVweFVgnADaMtKYK8yymIo+QmeqmuUVMjFP1l0ca7wW8A9YZWAjD1bKx xsvOFfIkZfEl5CxwYlLcH+e5csgr+aWNmiTvgeDxIp6i0OaWnWIc4qAU61NqNgxSI8oJ pf6Qug7nGTZrIYw064EmUjbmIqYC2q33iEnX4sklQQHktWRY1gM1slZHhHQUB8/lEEp0 gW5g== X-Gm-Message-State: AOUpUlEKrtlJ/eXMk7wv+Ym3LRFxUseyt3OfmldyKqBr+0A1POY9h6qW 0Uw9Q9Nf3B9yMK/YYHdFLgId/g== X-Google-Smtp-Source: AAOMgpeDLN3wf5IeEkZNAzQxRDoFvqbyq1IlL3cCULB9Bm6J8j0uDTc+1FjzIftvLJ3+G9QtTrn7+Q== X-Received: by 2002:a17:902:7683:: with SMTP id m3-v6mr22545198pll.255.1532563169664; Wed, 25 Jul 2018 16:59:29 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:8d38]) by smtp.gmail.com with ESMTPSA id 65-v6sm23188753pfq.81.2018.07.25.16.59.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 16:59:29 -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 v4 2/9] proc/kcore: don't grab lock for memory hotplug notifier Date: Wed, 25 Jul 2018 16:59:13 -0700 Message-Id: <93fa8dc895f40f2b85d706779b3cd2902567ff7a.1532563124.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. Reviewed-by: Andrew Morton 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; }