Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2694392lqt; Mon, 22 Apr 2024 20:41:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6cUL1IfsvtHcIMZgY8rDzXc2B5xU3Oq9HU+C3jZz63627XxAjW6U3/M6DdvOQdledZnHo1Zo0xWlUTc8bJnCBYsuBZbY3cEOyIlgxtA== X-Google-Smtp-Source: AGHT+IE9GdzLcWbkPT+nLdeFsmn2eFFMp18AvksKDij/1DLwlU+JvKdsMNE9aRh98VR4PJ5ilLTk X-Received: by 2002:a17:903:2290:b0:1e4:49:de46 with SMTP id b16-20020a170903229000b001e40049de46mr13844632plh.47.1713843701617; Mon, 22 Apr 2024 20:41:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713843701; cv=pass; d=google.com; s=arc-20160816; b=HHlmZR1cAnHBaRhntZbXei5ajpSAtguBU7AZiQHv6ENwmhLp8OW8WQ8Du7weCXZ//w tO/FZZ6beFfYU0o5EexTZXYP6N1wjSoZzR4nCRcf577/cWNVzQquDMrjHvgh9JNydOis yrw7uBfyN5K9nGRLaAeT9kkgay6xjIi523uxjf34BkvBOHo+OuK/zR94QLIcY9LsSrUS pKekE5VllZtKbAEj+KbOkTRppGHcmevtBuW+nQOFIpURG7Ik4ERfkAvpyOn1O3GoVmPQ SMcHELu9HbXUILQqmBmxw26fdEP1ZTwIGjJqBZ5i3CRrPVoHL1G0fnXqdkbxoGVm2dmi DJTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KkBGMpzb7Zyfmx1ZstJgk5Op8ktl/5dFs5p8PlYlyX8=; fh=8j3cshPcKC8dh7LNhAimwJd791iUI4B10zfUQz02DzE=; b=Tl4Sc7QaJlsAS/+dnDAJ/a2StevCONSonLlAGGWTtU8orWMJoSfoUiI5B+ZXzbMWtM zYDSyp9EuCJ3mG2mNsQweFIDhwAPOQ1YHz26h9EcVXcMLcRCDsMAPH2Ku0uCY8ukHAaq ARMr71bUUyvOS7BoRaNggydjKesw2/+aopnllH8PUFONLbEadVpUM0ZOAxII9LBq0JF7 Gotjzl0lWQXophQlYss9mBgs6SOAHKZf+lfr7hMykDmNKJloIctiZTyrZh6Cc7lK2DwM JG6eWCwfrBeMxt5ge69KwbSe8ED+o03HQN6WVbCWJH/O/IKLjf1GmKX0FyvU92i4qATM BC3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=eNp82nlB; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-154463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n1-20020a170902d2c100b001e92149978bsi5315410plc.38.2024.04.22.20.41.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 20:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=eNp82nlB; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-154463-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154463-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1796828385C for ; Tue, 23 Apr 2024 03:41:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B66A11CFA8; Tue, 23 Apr 2024 03:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="eNp82nlB" Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 619F81CA82 for ; Tue, 23 Apr 2024 03:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713843682; cv=none; b=rCDsvZ20i40GNLveR42fK+Ucvsvcb4Hb7JLp3oh/wZ2bd5Oy2exLjI1BeQ91/d9hCkM4DiPjpeUsMlXoy5+hmBuCr7R1A3415QelM9XEyQiWIAsbryNiin3/hJeuVOxGyiOqdKuhBUKTyfYFTVyGR7UADu/9oZzOIRAWeQUlGVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713843682; c=relaxed/simple; bh=iSysrDVuYXg0UMc79wYI1kULCvYs69ZhGh9/V1D5h+s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AUz+4ZReggx4D+NfOGc8mhlI5oFQtZKbGpc0fhEZ5yFC5sIMf9c/zeCRGzHr9JRSCsrgcRKIKnKo6Wk4DLULRWmdke4zTkPsi4YgxSUXBWvXuZNaT+zL3Do9DZ7E5QR+KRPtlFp35vQICuy3eXfkAXRr3Xl3zKhoPir0kj6xh8U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=eNp82nlB; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6ea26393116so3362132a34.0 for ; Mon, 22 Apr 2024 20:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1713843680; x=1714448480; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KkBGMpzb7Zyfmx1ZstJgk5Op8ktl/5dFs5p8PlYlyX8=; b=eNp82nlBJNHzj3Yh79uzhq7zJoIKFlmg9pMmQWYf8K/RsEBOyR4ekwf0wM5i4sbX5d Z8nn9f7Uyay3jD5e2r5o3q61beKYFK7i95QtRx+9thKnACyVYU2k2XPSquyR9WdygDJR g2ajt8UTJ80rYf0dajsHKt2VPmjsD2MXdql1NI/k4oposkFxBH1jJqibNdZYB2JK3Xaa W8fxUD4eCsoAHQBchl49THouhe4lEr4AE9QSVqBV1m7ksV/YqkllmYTcz1/Ytp2NJzEs MFu0nzRkGk6iGKouEIDDrMmrw8bmib4qkviIwpgZT+n+HDkWgQB4OjzfbZ1/EyLfiTNq VP7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713843680; x=1714448480; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KkBGMpzb7Zyfmx1ZstJgk5Op8ktl/5dFs5p8PlYlyX8=; b=B8KRJmSEvpNTE3sc6UhzxgvdCzVznFVw/i5Y48w3HJ+lfLHEgCbZA1OORMKX+fM5Oj 2NYS8M0vXhyciT5QJdknis3RkrIjqAqtAjTvc37evFLqawtiDu4+6klcmvsQ69RX7UeT JWGwqjgtSSeX083nCWVBoUSfyDOLRXEZ2YkoFUH9ZzCoZApnYs2TQzNS2TcCKQlY7Njo hzllhMIpTbFI63ZRd29STBpITPEvQbU8Mxdu+4smZ81+jqCPxp0uNyyrdRAv5NPEhDHT kwqeFau63ddcLZXrXgZnVcGS9EzWx38uvIkfBMjOD80kGOysw4wIzivAUOv8ALJtpbmR coJg== X-Gm-Message-State: AOJu0Yz1OLD3yhtitOr6jWBB62iiDvPMMGOPxfD4mNVmBKhKm7Kspr4v niusKmOiEF7aFXjCdyuxSpyVecz1ATfzCGXTLEp194BDFMSbMLtXfAhmM0WwUoFe09jFUd8Rc2U 4 X-Received: by 2002:a05:6830:4392:b0:6ed:686:b43 with SMTP id s18-20020a056830439200b006ed06860b43mr9633062otv.17.1713843680244; Mon, 22 Apr 2024 20:41:20 -0700 (PDT) Received: from libai.bytedance.net ([61.213.176.11]) by smtp.gmail.com with ESMTPSA id b16-20020a63d810000000b005e438fe702dsm8266980pgh.65.2024.04.22.20.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 20:41:19 -0700 (PDT) From: zhenwei pi To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux.dev Cc: mst@redhat.com, david@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, akpm@linux-foundation.org, zhenwei pi Subject: [PATCH v3 1/4] virtio_balloon: separate vm events into a function Date: Tue, 23 Apr 2024 11:41:06 +0800 Message-Id: <20240423034109.1552866-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240423034109.1552866-1-pizhenwei@bytedance.com> References: <20240423034109.1552866-1-pizhenwei@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit All the VM events related statistics have dependence on 'CONFIG_VM_EVENT_COUNTERS', separate these events into a function to make code clean. Then we can remove 'CONFIG_VM_EVENT_COUNTERS' from 'update_balloon_stats'. Signed-off-by: zhenwei pi --- drivers/virtio/virtio_balloon.c | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 1f5b3dd31fcf..1710e3098ecd 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -316,34 +316,49 @@ static inline void update_stat(struct virtio_balloon *vb, int idx, #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT) -static unsigned int update_balloon_stats(struct virtio_balloon *vb) +#ifdef CONFIG_VM_EVENT_COUNTERS +/* Return the number of entries filled by vm events */ +static inline unsigned int update_balloon_vm_stats(struct virtio_balloon *vb) { unsigned long events[NR_VM_EVENT_ITEMS]; - struct sysinfo i; unsigned int idx = 0; - long available; - unsigned long caches; all_vm_events(events); - si_meminfo(&i); - - available = si_mem_available(); - caches = global_node_page_state(NR_FILE_PAGES); - -#ifdef CONFIG_VM_EVENT_COUNTERS update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, - pages_to_bytes(events[PSWPIN])); + pages_to_bytes(events[PSWPIN])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT, - pages_to_bytes(events[PSWPOUT])); + pages_to_bytes(events[PSWPOUT])); update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]); update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]); + #ifdef CONFIG_HUGETLB_PAGE update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGALLOC, events[HTLB_BUDDY_PGALLOC]); update_stat(vb, idx++, VIRTIO_BALLOON_S_HTLB_PGFAIL, events[HTLB_BUDDY_PGALLOC_FAIL]); -#endif -#endif +#endif /* CONFIG_HUGETLB_PAGE */ + + return idx; +} +#else /* CONFIG_VM_EVENT_COUNTERS */ +static inline unsigned int update_balloon_vm_stats(struct virtio_balloon *vb) +{ + return 0; +} +#endif /* CONFIG_VM_EVENT_COUNTERS */ + +static unsigned int update_balloon_stats(struct virtio_balloon *vb) +{ + struct sysinfo i; + unsigned int idx; + long available; + unsigned long caches; + + idx = update_balloon_vm_stats(vb); + + si_meminfo(&i); + available = si_mem_available(); + caches = global_node_page_state(NR_FILE_PAGES); update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE, pages_to_bytes(i.freeram)); update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT, -- 2.34.1