Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1365072imm; Wed, 25 Jul 2018 17:02:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfYbssB4hcMQEyqYOIzenxCO+SdNT3pSnFRLJjo9qCnet8cSVVHJnck6eG5y0OzPxNF+5v0 X-Received: by 2002:a63:1a20:: with SMTP id a32-v6mr8591477pga.446.1532563374770; Wed, 25 Jul 2018 17:02:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532563374; cv=none; d=google.com; s=arc-20160816; b=ZiMG+bYFsLeBajEH7DFVyQaGI69/K0AkDX6+D7o96sIaWoja1QmrcaqHSgg9hBoGkh xvf7tSKcv2GoX85c8TbVZPacqNdR9mtYnTpXo88j66QsNveaHO9uN/5hwOLp0sGVyr9+ pJxHSFckOPdtcJfMdzZqlROmp7+cJbDWB3WzHT1KfG4o3tRSyHgqIukuT9ATI+wRDCpk fF32Ex2aMcDSogGWPpIgEbXbDopfNTkDU8681rd074fHGac+v5c1o+Dg4MQu9iIDXgcl +xGh37T/x9gZ6FYKKbacv31BBHIODzi/K6SO79FDklrqNfTbdZbqealYMvK2XzMmnw04 CJTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=16w7KIxIKq7DVWU2jRPaeALdZ2xcgpzjcsj3qPwpVus=; b=DK3h/DHFHGaGrnBjbL6q2sILoAKJQFy3b1WcNMMQtMWh2SJoAJEMnrLD+N3CzoBPJb 64UAEVo+Go00N4KjSztuqgmiJAtnn3y3csnKu0PuwHtyuKcN2NrsQkMd7Ll9mmnOdCbV +ZiX/5RzA4uiXXtdnlvS/oK1RofuY93eHTcIXQ13+dfI8/5m+r0J6l0Ms4F+Wdrn9PV9 H+ceGcAEkKk+tneeYLEVowPyqVVIxaBnB54ugqtsZndCcoaLT14FBtM0pMMyPvff4f4C ZZm+wm+e0k1PCf2mJTGd0LOuHShnS9emRHE6CS0mdrU7s12/XlrymOmP3t0/jKA+GMkX Q6hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=H8lv7CQz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 85-v6si15051399pfm.264.2018.07.25.17.02.40; Wed, 25 Jul 2018 17:02:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=H8lv7CQz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728563AbeGZBNg (ORCPT + 99 others); Wed, 25 Jul 2018 21:13:36 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:36739 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728486AbeGZBNe (ORCPT ); Wed, 25 Jul 2018 21:13:34 -0400 Received: by mail-pl0-f67.google.com with SMTP id e11-v6so3951433plb.3 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=X1EtfkDhAYwA3UAgLyPnp8+n+EHlVwPcJUy6YiGGbuNm9F+Lr3pn1XByqSMjmQ3asQ V63rszrCnuXhMsxmHbzQo68fGAhKm9r28aqw2vtMAxcEqNNGZEAHyKuFjz3ANAo/0XWY o/e5+SxEc0I2kICrNptcol/79c+pAyl/ItaSDMctI8zP8nuWSpgwTnMUPwA+0k0iLvLW 7ItXhgnFf9JKmG3wGp2sLlXpKOxx1SImZ4ESakaFJ9FpKzZrUZ/RQ9IggCehgoZt4vTC qqH3wW30QsVMzkmxVsNTsvgDAu65Dq16q7m4oGeZ51nbhD/Edd6lGy2KWWxUE/jKH89Q XWEQ== X-Gm-Message-State: AOUpUlHM9ipppLb5+mdNc4mtPx2pFzPtELxEK0EtUyUhS7nbCFi6wpHV 1UE4F0JzKKEWnmYvfAp0URjBtFgnYFc= 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.18.0