From patchwork Tue Apr 2 07:41:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10881197 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 52EE9922 for ; Tue, 2 Apr 2019 07:42:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C58728740 for ; Tue, 2 Apr 2019 07:42:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A51B2889B; Tue, 2 Apr 2019 07:42: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,FREEMAIL_FROM,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 7829928898 for ; Tue, 2 Apr 2019 07:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728797AbfDBHmH (ORCPT ); Tue, 2 Apr 2019 03:42:07 -0400 Received: from mout.gmx.net ([212.227.15.19]:45287 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbfDBHmG (ORCPT ); Tue, 2 Apr 2019 03:42:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1554190918; bh=8hwxpfhjKorqYj9TqNfgVEXtaIDiMGikvfkOyC2TafA=; h=X-UI-Sender-Class:To:From:Subject:Date; b=IgYl3gtPJ2AELRuyoEZK8+w5r0K+G2XfPHPpbdX7ijB5i30T5e8YeWUhS9601DkBX LVidvEwxXebVPbj8uN0A0ef3FqzkiKozhPkmRydBesvknECaAnCEesaRkkAKlPRD8L nAAyQ51oez9/jvnaGeCiQdVlNRuxHQdczqCWk/rU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [0.0.0.0] ([210.140.77.29]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LoVOE-1giClj2ebK-00gaEt; Tue, 02 Apr 2019 09:41:58 +0200 To: "linux-btrfs@vger.kernel.org" , iovisor-dev@lists.iovisor.org From: Qu Wenruo Subject: Is it a good idea to export certain internal structure declaration to make bcc/ebpf happier? Openpgp: preference=signencrypt Autocrypt: addr=quwenruo.btrfs@gmx.com; prefer-encrypt=mutual; keydata= mQENBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEdHvN0Kov3CtWA+R1iNN0RCeVun7rmOrrjBK573aWC5sgP7YsBOLK79H3tmUtz6b 9Imuj0ZyEsa76Xg9PX9Hn2myKj1hfWGS+5og9Va4hrwQC8ipjXik6NKR5GDV+hOZkktU81G5 gkQtGB9jOAYRs86QG/b7PtIlbd3+pppT0gaS+wvwMs8cuNG+Pu6KO1oC4jgdseFLu7NpABEB AAG0IlF1IFdlbnJ1byA8cXV3ZW5ydW8uYnRyZnNAZ214LmNvbT6JAVQEEwEIAD4CGwMFCwkI BwIGFQgJCgsCBBYCAwECHgECF4AWIQQt33LlpaVbqJ2qQuHCPZHzoSX+qAUCWdWCnQUJCWYC bgAKCRDCPZHzoSX+qAR8B/94VAsSNygx1C6dhb1u1Wp1Jr/lfO7QIOK/nf1PF0VpYjTQ2au8 ihf/RApTna31sVjBx3jzlmpy+lDoPdXwbI3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com> Date: Tue, 2 Apr 2019 15:41:52 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 X-Provags-ID: V03:K1:piKi2U1osGpIZGRGPCRsrBlGUPtZ66Nt50+n4hSJrupf2A01ucq 7m4ywoa/FvGu3+PlM12HhSpD5pX1xnhEYOXBkQkpIwhRSwXjMXreHY+71lCwWYvswVzUaSR AN8QmZdEL0nyZ/zI3cFHpsMKni7hUdGPerffB/fnkW7YIM3nR1qjYGPc6kEpfuYH8lrkG6p awN+MRII+awWukMDbvHuw== X-UI-Out-Filterresults: notjunk:1;V03:K0:hpT4B3KcmV4=:zKe7m/mpG5yyMMUwvTBSo5 WEPwcdCWx7bkR4RtGPxz2l5r2f3hzgoW4O0YNUrL94X+PgiVw8+/uCVu1NyHqi4bu8PsnPbLL LrGJvDHtVw65GLkUTvP9WccsiGEisAaXvHFZxo7erfmmKisrzW9INKLrA+9cGo3W/Dlxu+QqW vX1VWoXz2sKAnJyRdqIKLc5pi8TBbkqKOh/LWXUzu5kXJTrMt+7xwauDxUc7CZ54wG2S1ezyp II8Oy4qBSMawECBHXz6QuYERbPDElmKOmHwsQOaW9KMGF2UTnatu5cbm8HZA4XKjDE9Es1ZBW sIYvfpvPODy02kV2/rEeqnQ+mPWXbwWjFiMYYcxPaCR1bc+N0RhES0CtyrybjGMzigyeKs+G4 N2E5QciqG2JnAQT1sX6S/fL2yNwFy+IHIUCCuykh9XHAmEUGOZBC7+8iGDE85EGTH/oOeK6Gf MLPml7EXlY8Yq3hwY336F3YjMxPyf06pzCbCMlpdnOdDUonVmhoN+wVStNKFEQlAG046YnMnX 1FP7F8lzNSPesOWV4guKM5mW/6EWoHhYqcyr0Q7wK77K33WyOfB7Tnh23A9/6Bwx6wukItKpp fkndLuCSQ6nyiMJlCRXkkgwK5zy4sRl/NwwPaWZTP8Ep807C8r8AQLqw/csLF2DF5THDy6hIm 8ETtwujZDruvr8fBBCCK8Xf840wVBZqAAy9drIuQmQTHY/rwNEFmleWsX3dVIyMoaR89YPodb mjpHOyxD3asgJ1nThcP7D3PixDCBxKwPpcbvswS28RdGpIol+ykzJgyU39abOKbaqrglmHfO/ Fy8qYUWh1ICTXssgF1JSZysFlZRREH6RFybFQn3Vcpl97P/fErpyLcbusL312jlBsP+QLkdyc eLatNmbadO+e9epnt4t+k4a7JP52JYIPGe5hbWhLPO2HR2rWf7Ji+0MTMfNh6x Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, I'm recently working on crafting a small bcc based script to show how btrfs tree block concurrency. The prototype is here: https://gist.github.com/adam900710/63db6cdc7d26c4744a53dfc7755fafda However it has some problems, and cannot be used directly on latest kernel. - No way to pass btrfs headers into eBPF code. This is because the declaration of extent_buffer is in `fs/btrfs/extent_io.h`. No in the common kernel headers search path. - eBPF program can't access btrfs_header_owner() helper. Even we make eBPF code understand the headers, we can't access a lot of kernel functions, like btrfs_header_owner(). So I'm wondering is it possible for us to export extent_buffer declaration just for possible eBPF usage. Or is bcc suit strong enough to handle such case? The diff would be something like this to make above bcc script work: #endif /* _UAPI_LINUX_BTRFS_H */ Thanks, Qu diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index a3e3e95c632e..ba7628434ac9 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "extent_io.h" #include "extent_map.h" #include "ctree.h" diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index c4ec104ac157..5bc0df2c1c64 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -146,48 +146,6 @@ struct extent_state { #endif }; -#define INLINE_EXTENT_BUFFER_PAGES 16 -#define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_SIZE) -struct extent_buffer { - u64 start; - unsigned long len; - unsigned long bflags; - struct btrfs_fs_info *fs_info; - spinlock_t refs_lock; - atomic_t refs; - atomic_t io_pages; - int read_mirror; - struct rcu_head rcu_head; - pid_t lock_owner; - - atomic_t blocking_writers; - atomic_t blocking_readers; - bool lock_nested; - /* >= 0 if eb belongs to a log tree, -1 otherwise */ - short log_index; - - /* protects write locks */ - rwlock_t lock; - - /* readers use lock_wq while they wait for the write - * lock holders to unlock - */ - wait_queue_head_t write_lock_wq; - - /* writers use read_lock_wq while they wait for readers - * to unlock - */ - wait_queue_head_t read_lock_wq; - struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; -#ifdef CONFIG_BTRFS_DEBUG - atomic_t spinning_writers; - atomic_t spinning_readers; - atomic_t read_locks; - atomic_t write_locks; - struct list_head leak_list; -#endif -}; - /* * Structure to record how many bytes and which ranges are set/cleared */ diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c index 6df03ba36026..5cf075d02b1b 100644 --- a/fs/btrfs/locking.c +++ b/fs/btrfs/locking.c @@ -174,6 +174,8 @@ void btrfs_tree_read_lock(struct extent_buffer *eb) BUG_ON(eb->lock_nested); eb->lock_nested = true; read_unlock(&eb->lock); + if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) + eb->owner = btrfs_header_owner(eb); return; } if (atomic_read(&eb->blocking_writers)) { @@ -184,6 +186,8 @@ void btrfs_tree_read_lock(struct extent_buffer *eb) } btrfs_assert_tree_read_locks_get(eb); btrfs_assert_spinning_readers_get(eb); + if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) + eb->owner = btrfs_header_owner(eb); } /* @@ -312,6 +316,8 @@ void btrfs_tree_lock(struct extent_buffer *eb) btrfs_assert_spinning_writers_get(eb); btrfs_assert_tree_write_locks_get(eb); eb->lock_owner = current->pid; + if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) + eb->owner = btrfs_header_owner(eb); } /* diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index c195896d478f..3aeaffdadabb 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -944,4 +944,47 @@ enum btrfs_err_code { #define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \ struct btrfs_ioctl_ino_lookup_user_args) +#define INLINE_EXTENT_BUFFER_PAGES 16 +#define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_SIZE) +struct extent_buffer { + u64 start; + unsigned long len; + unsigned long bflags; + struct btrfs_fs_info *fs_info; + spinlock_t refs_lock; + atomic_t refs; + atomic_t io_pages; + int read_mirror; + struct rcu_head rcu_head; + pid_t lock_owner; + + atomic_t blocking_writers; + atomic_t blocking_readers; + bool lock_nested; + /* >= 0 if eb belongs to a log tree, -1 otherwise */ + short log_index; + + /* protects write locks */ + rwlock_t lock; + + /* readers use lock_wq while they wait for the write + * lock holders to unlock + */ + wait_queue_head_t write_lock_wq; + + /* writers use read_lock_wq while they wait for readers + * to unlock + */ + wait_queue_head_t read_lock_wq; + struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; +#ifdef CONFIG_BTRFS_DEBUG + atomic_t spinning_writers; + atomic_t spinning_readers; + atomic_t read_locks; + atomic_t write_locks; + u64 owner; + struct list_head leak_list; +#endif +}; +