Skip to content

Commit 76a8337

Browse files
committed
Updating based on PR Feedback(1)
Updating code based on PR code comments. I adjusted the following parts of code based on comments: 1. Revert dbuf_undirty() to original logic and got rid of uncessary code change. 2. Cleanup in abd_impl.h 3. Cleanup in abd.h 4. Got rid of duplicate declaration of dmu_buf_hold_noread() in dmu.h. 5. Cleaned up comment for db_mtx in dmu_imp.h 6. Updated zfsprop man page to state correct ZFS version 7. Updated to correct cast in zfs_uio_page_aligned() calls to use uintptr_t. 8. Cleaned up comment in FreeBSD uio code. 9. Removed unnecessary format changes in comments in Linux abd code. 10. Updated ZFS VFS hook for direct_IO to use PANIC(). 11. Updated comment above dbuf_undirty to use double space again. 12. Converted module paramter zfs_vdev_direct_write_verify_pct OS indedepent and in doing so this removed the uneccessary check for bounds. 13. Updated to casting in zfs_dio_page_aligned to uniptr_t and added kernel guard. 14. Updated zfs_dio_size_aligned() to use modulo math because dn->dn_datablksz is not required to be a power of 2. 15. Removed abd scatter stats update calls from all ABD_FLAG_FROM_PAGES. 16. Updated check in abd_alloc_from_pages() for the linear page. This way a single page that is even 4K can represented as an ABD_FLAG_LINEAR_PAGE. 17. Updated npages in zfs_uio_dio_t struct to be size_t. Signed-off-by: Brian Atkinson <[email protected]>
1 parent 9909121 commit 76a8337

File tree

21 files changed

+74
-169
lines changed

21 files changed

+74
-169
lines changed

include/os/freebsd/spl/sys/mod_os.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@
100100
#define spa_taskq_write_param_set_args(var) \
101101
CTLTYPE_STRING, NULL, 0, spa_taskq_write_param, "A"
102102

103-
#define param_set_direct_write_verify_pct_args(var) \
104-
CTLTYPE_UINT, NULL, 0, param_set_direct_write_verify_pct, "IU"
105-
106103
#define fletcher_4_param_set_args(var) \
107104
CTLTYPE_STRING, NULL, 0, fletcher_4_param, "A"
108105

include/os/freebsd/spl/sys/uio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef enum uio_rw zfs_uio_rw_t;
5050
*/
5151
typedef struct {
5252
vm_page_t *pages;
53-
int npages;
53+
size_t npages;
5454
} zfs_uio_dio_t;
5555

5656
typedef struct zfs_uio {

include/os/linux/spl/sys/uio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef enum zfs_uio_seg {
6565
*/
6666
typedef struct {
6767
struct page **pages; /* Mapped pages */
68-
int npages; /* Number of mapped pages */
68+
size_t npages; /* Number of mapped pages */
6969
} zfs_uio_dio_t;
7070

7171
typedef struct zfs_uio {

include/sys/abd.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
extern "C" {
3535
#endif
3636

37+
#if defined(__FreeBSD__) && defined(_KERNEL)
3738
struct sf_buf;
39+
#endif
3840

3941
typedef enum abd_flags {
4042
ABD_FLAG_LINEAR = 1 << 0, /* is buffer linear (or scattered)? */
@@ -71,8 +73,11 @@ typedef struct abd {
7173
} abd_scatter;
7274
struct abd_linear {
7375
void *abd_buf;
74-
struct scatterlist *abd_sgl; /* for LINEAR_PAGE Linux */
76+
#if defined(__FreeBSD__) && defined(_KERNEL)
7577
struct sf_buf *sf; /* for LINEAR_PAGE FreeBSD */
78+
#else
79+
struct scatterlist *abd_sgl; /* for LINEAR_PAGE Linux */
80+
#endif
7681
} abd_linear;
7782
struct abd_gang {
7883
list_t abd_gang_chain;

include/sys/abd_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ struct abd_iter {
7272
size_t iter_pos;
7373
size_t iter_offset; /* offset in current sg/abd_buf, */
7474
/* abd_offset included */
75-
struct scatterlist *iter_sg; /* current sg */
7675
#if defined(__FreeBSD__) && defined(_KERNEL)
7776
struct sf_buf *sf; /* used to map in vm_page_t FreeBSD */
77+
#else
78+
struct scatterlist *iter_sg; /* current sg */
7879
#endif
7980
};
8081

include/sys/dmu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,6 @@ int dmu_spill_hold_existing(dmu_buf_t *bonus, const void *tag, dmu_buf_t **dbp);
568568
*
569569
* The object number must be a valid, allocated object number.
570570
*/
571-
int dmu_buf_hold_noread(objset_t *os, uint64_t object, uint64_t offset,
572-
const void *tag, dmu_buf_t **dbp);
573571
int dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
574572
const void *tag, dmu_buf_t **, int flags);
575573
int dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset,

include/sys/dmu_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ extern "C" {
138138
* db_data_pending
139139
* db_dirtied
140140
* db_link
141-
* dbuf_dirty_records
141+
* db_dirty_records
142142
* db_dirtycnt
143143
* db_d.*
144144
* db.*

include/sys/uio_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ extern void zfs_uio_free_dio_pages(zfs_uio_t *, zfs_uio_rw_t);
4949
extern int zfs_uio_get_dio_pages_alloc(zfs_uio_t *, zfs_uio_rw_t);
5050
extern boolean_t zfs_uio_page_aligned(zfs_uio_t *);
5151

52+
#ifdef _KERNEL
5253
static inline boolean_t
5354
zfs_dio_page_aligned(void *buf)
5455
{
55-
return ((((unsigned long)(buf) & (PAGESIZE - 1)) == 0) ?
56+
return ((((uintptr_t)(buf) & (PAGESIZE - 1)) == 0) ?
5657
B_TRUE : B_FALSE);
5758
}
59+
#endif
5860

5961
static inline boolean_t
6062
zfs_dio_offset_aligned(uint64_t offset, uint64_t blksz)
@@ -65,7 +67,7 @@ zfs_dio_offset_aligned(uint64_t offset, uint64_t blksz)
6567
static inline boolean_t
6668
zfs_dio_size_aligned(uint64_t size, uint64_t blksz)
6769
{
68-
return (IS_P2ALIGNED(size, blksz));
70+
return ((size % blksz) == 0);
6971
}
7072

7173
static inline boolean_t

include/sys/vdev_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ int param_set_max_auto_ashift(ZFS_MODULE_PARAM_ARGS);
658658
* VDEV checksum verification precentage for Direct I/O writes
659659
*/
660660
extern uint_t zfs_vdev_direct_write_verify_pct;
661-
int param_set_direct_write_verify_pct(ZFS_MODULE_PARAM_ARGS);
662661

663662
#ifdef __cplusplus
664663
}

lib/libspl/include/sys/uio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ zfs_dio_offset_aligned(uint64_t offset, uint64_t blksz)
9898
static inline boolean_t
9999
zfs_dio_size_aligned(uint64_t size, uint64_t blksz)
100100
{
101-
return (IS_P2ALIGNED(size, blksz));
101+
return ((size % blksz) == 0);
102102
}
103103

104104
static inline boolean_t

man/man7/zfsprops.7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ causes every properly aligned read or write to be treated as a direct request.
10541054
.Sy disabled
10551055
causes the O_DIRECT flag to be silently ignored and all direct requests will
10561056
be handled by the ARC.
1057-
This is the default behavior for OpenZFS 2.1 and prior releases.
1057+
This is the default behavior for OpenZFS 2.2 and prior releases.
10581058
.Pp
10591059
Bypassing the ARC requires that a direct request be correctly aligned.
10601060
For write requests the starting offset and size of the request must be

module/Kbuild.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ ZFS_OBJS_OS := \
445445
vdev_disk.o \
446446
vdev_file.o \
447447
vdev_label_os.o \
448-
vdev_os.o \
449448
zfs_acl.o \
450449
zfs_ctldir.o \
451450
zfs_debug.o \

module/os/freebsd/spl/spl_uio.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ zfs_uio_page_aligned(zfs_uio_t *uio)
119119
const struct iovec *iov = GET_UIO_STRUCT(uio)->uio_iov;
120120

121121
for (int i = zfs_uio_iovcnt(uio); i > 0; iov++, i--) {
122-
unsigned long addr = (unsigned long)iov->iov_base;
122+
uintptr_t addr = (uintptr_t)iov->iov_base;
123123
size_t size = iov->iov_len;
124124
if ((addr & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1))) {
125125
return (B_FALSE);
@@ -140,7 +140,7 @@ zfs_uio_set_pages_to_stable(zfs_uio_t *uio)
140140

141141
obj = uio->uio_dio.pages[0]->object;
142142
zfs_vmobject_wlock(obj);
143-
for (int i = 0; i < uio->uio_dio.npages; i++) {
143+
for (size_t i = 0; i < uio->uio_dio.npages; i++) {
144144
vm_page_t page = uio->uio_dio.pages[i];
145145

146146
ASSERT3P(page, !=, NULL);
@@ -160,7 +160,7 @@ static void
160160
zfs_uio_release_stable_pages(zfs_uio_t *uio)
161161
{
162162
ASSERT3P(uio->uio_dio.pages, !=, NULL);
163-
for (int i = 0; i < uio->uio_dio.npages; i++) {
163+
for (size_t i = 0; i < uio->uio_dio.npages; i++) {
164164
vm_page_t page = uio->uio_dio.pages[i];
165165

166166
ASSERT3P(page, !=, NULL);
@@ -177,7 +177,7 @@ zfs_uio_set_pages_to_stable(zfs_uio_t *uio)
177177
ASSERT3P(uio->uio_dio.pages, !=, NULL);
178178
ASSERT3U(uio->uio_dio.npages, >, 0);
179179

180-
for (int i = 0; i < uio->uio_dio.npages; i++) {
180+
for (size_t i = 0; i < uio->uio_dio.npages; i++) {
181181
vm_page_t page = uio->uio_dio.pages[i];
182182
ASSERT3P(page, !=, NULL);
183183

@@ -191,7 +191,7 @@ static void
191191
zfs_uio_release_stable_pages(zfs_uio_t *uio)
192192
{
193193
ASSERT3P(uio->uio_dio.pages, !=, NULL);
194-
for (int i = 0; i < uio->uio_dio.npages; i++) {
194+
for (size_t i = 0; i < uio->uio_dio.npages; i++) {
195195
vm_page_t page = uio->uio_dio.pages[i];
196196

197197
ASSERT3P(page, !=, NULL);
@@ -205,13 +205,13 @@ zfs_uio_release_stable_pages(zfs_uio_t *uio)
205205
* If the operation is marked as read, then we are stating the pages will be
206206
* written to and must be given write access.
207207
*/
208-
static int
209-
zfs_uio_hold_pages(unsigned long start, size_t len, unsigned long nr_pages,
208+
static size_t
209+
zfs_uio_hold_pages(unsigned long start, size_t len, size_t nr_pages,
210210
zfs_uio_rw_t rw, vm_page_t *pages)
211211
{
212212
vm_map_t map;
213213
vm_prot_t prot;
214-
int count;
214+
size_t count;
215215

216216
map = &curthread->td_proc->p_vmspace->vm_map;
217217
ASSERT3S(len, >, 0);
@@ -224,10 +224,10 @@ zfs_uio_hold_pages(unsigned long start, size_t len, unsigned long nr_pages,
224224
}
225225

226226
static void
227-
zfs_uio_unhold_pages(vm_page_t *m, int count)
227+
zfs_uio_unhold_pages(vm_page_t *m, size_t count)
228228
{
229229
#if __FreeBSD_version < 1300050
230-
for (int i = 0; i < count; i++) {
230+
for (size_t i = 0; i < count; i++) {
231231
vm_page_t page = m[i];
232232
ASSERT3P(page, !=, NULL);
233233
vm_page_lock(page);
@@ -256,11 +256,11 @@ zfs_uio_free_dio_pages(zfs_uio_t *uio, zfs_uio_rw_t rw)
256256
uio->uio_dio.npages * sizeof (vm_page_t));
257257
}
258258

259-
static long
260-
zfs_uio_get_user_pages(unsigned long start, unsigned long nr_pages,
259+
static size_t
260+
zfs_uio_get_user_pages(unsigned long start, size_t nr_pages,
261261
size_t len, zfs_uio_rw_t rw, vm_page_t *pages)
262262
{
263-
int count;
263+
size_t count;
264264

265265
count = zfs_uio_hold_pages(start, len, nr_pages, rw, pages);
266266

@@ -286,21 +286,20 @@ zfs_uio_get_user_pages(unsigned long start, unsigned long nr_pages,
286286
}
287287

288288
static size_t
289-
zfs_uio_iov_step(struct iovec v, zfs_uio_t *uio, int *numpages)
289+
zfs_uio_iov_step(struct iovec v, zfs_uio_t *uio, size_t *numpages)
290290
{
291291
unsigned long addr = (unsigned long)(v.iov_base);
292292
size_t len = v.iov_len;
293-
int n = DIV_ROUND_UP(len, PAGE_SIZE);
293+
size_t n = DIV_ROUND_UP(len, PAGE_SIZE);
294294

295-
int res = zfs_uio_get_user_pages(
295+
size_t res = zfs_uio_get_user_pages(
296296
P2ALIGN_TYPED(addr, PAGE_SIZE, unsigned long), n, len,
297297
zfs_uio_rw(uio), &uio->uio_dio.pages[uio->uio_dio.npages]);
298298
if (res != n) {
299-
*numpages = -1;
300-
return (SET_ERROR(EFAULT));
299+
return (0);
301300
}
302301

303-
ASSERT3S(len, ==, res * PAGE_SIZE);
302+
ASSERT3U(len, ==, res * PAGE_SIZE);
304303
*numpages = res;
305304
return (len);
306305
}
@@ -316,7 +315,7 @@ zfs_uio_get_dio_pages_impl(zfs_uio_t *uio)
316315

317316
for (int i = 0; i < zfs_uio_iovcnt(uio); i++) {
318317
struct iovec iov;
319-
int numpages = 0;
318+
size_t numpages = 0;
320319

321320
if (iovp->iov_len == 0) {
322321
iovp++;
@@ -326,8 +325,8 @@ zfs_uio_get_dio_pages_impl(zfs_uio_t *uio)
326325
iov.iov_base = iovp->iov_base;
327326
size_t left = zfs_uio_iov_step(iov, uio, &numpages);
328327

329-
if (numpages == -1)
330-
return (left);
328+
if (left == 0)
329+
return (SET_ERROR(EFAULT));
331330

332331
ASSERT3U(left, ==, iov.iov_len);
333332
uio->uio_dio.npages += numpages;
@@ -343,7 +342,7 @@ zfs_uio_get_dio_pages_impl(zfs_uio_t *uio)
343342

344343
/*
345344
* This function maps user pages into the kernel. In the event that the user
346-
* pages were not mapped successfully an error value is reutrned.
345+
* pages were not mapped successfully an error value is returned.
347346
*
348347
* On success, 0 is returned.
349348
*/

module/os/freebsd/zfs/abd_os.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,9 @@ abd_update_scatter_stats(abd_t *abd, abd_stats_op_t op)
144144
{
145145
uint_t n;
146146

147-
if (abd_is_from_pages(abd))
148-
n = abd_chunkcnt_for_bytes(abd->abd_size);
149-
else
150-
n = abd_scatter_chunkcnt(abd);
147+
n = abd_scatter_chunkcnt(abd);
151148
ASSERT(op == ABDSTAT_INCR || op == ABDSTAT_DECR);
152149
int waste = (n << PAGE_SHIFT) - abd->abd_size;
153-
ASSERT3U(n, >, 0);
154-
ASSERT3S(waste, >=, 0);
155-
IMPLY(abd_is_linear_page(abd), waste < PAGE_SIZE);
156150
if (op == ABDSTAT_INCR) {
157151
ABDSTAT_BUMP(abdstat_scatter_cnt);
158152
ABDSTAT_INCR(abdstat_scatter_data_size, abd->abd_size);
@@ -367,7 +361,6 @@ abd_free_linear_page(abd_t *abd)
367361
ASSERT3P(abd->abd_u.abd_linear.sf, !=, NULL);
368362
zfs_unmap_page(abd->abd_u.abd_linear.sf);
369363

370-
abd_update_scatter_stats(abd, ABDSTAT_DECR);
371364
#else
372365
/*
373366
* The ABD flag ABD_FLAG_LINEAR_PAGE should only be set in
@@ -477,14 +470,13 @@ abd_alloc_from_pages(vm_page_t *pages, unsigned long offset, uint64_t size)
477470
abd->abd_flags |= ABD_FLAG_OWNER | ABD_FLAG_FROM_PAGES;
478471
abd->abd_size = size;
479472

480-
if (size < PAGE_SIZE) {
473+
if ((offset + size) <= PAGE_SIZE) {
481474
/*
482-
* We do not have a full page so we will just use a linear ABD.
483-
* We have to make sure to take into account the offset though.
484-
* In all other cases our offset will be 0 as we are always
485-
* PAGE_SIZE aligned.
475+
* There is only a single page worth of data, so we will just
476+
* use a linear ABD. We have to make sure to take into account
477+
* the offset though. In all other cases our offset will be 0
478+
* as we are always PAGE_SIZE aligned.
486479
*/
487-
ASSERT3U(offset + size, <=, PAGE_SIZE);
488480
abd->abd_flags |= ABD_FLAG_LINEAR | ABD_FLAG_LINEAR_PAGE;
489481
ABD_LINEAR_BUF(abd) = (char *)zfs_map_page(pages[0],
490482
&abd->abd_u.abd_linear.sf) + offset;
@@ -499,8 +491,6 @@ abd_alloc_from_pages(vm_page_t *pages, unsigned long offset, uint64_t size)
499491
ABD_SCATTER(abd).abd_chunks[i] = pages[i];
500492
}
501493

502-
abd_update_scatter_stats(abd, ABDSTAT_INCR);
503-
504494
return (abd);
505495
}
506496

module/os/freebsd/zfs/sysctl_os.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -832,35 +832,6 @@ SYSCTL_PROC(_vfs_zfs, OID_AUTO, max_auto_ashift,
832832
" new top-level vdevs. (LEGACY)");
833833
/* END CSTYLED */
834834

835-
int
836-
param_set_direct_write_verify_pct(SYSCTL_HANDLER_ARGS)
837-
{
838-
int val;
839-
int err;
840-
841-
val = zfs_vdev_direct_write_verify_pct;
842-
err = sysctl_handle_int(oidp, &val, 0, req);
843-
if (err != 0 || req->newptr == NULL)
844-
return (SET_ERROR(err));
845-
846-
if (val > 100 || val < 0)
847-
return (SET_ERROR(EINVAL));
848-
849-
zfs_vdev_direct_write_verify_pct = val;
850-
851-
return (0);
852-
}
853-
854-
/* BEGIN CSTYLED */
855-
SYSCTL_PROC(_vfs_zfs, OID_AUTO, direct_write_verify_pct,
856-
CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
857-
&zfs_vdev_direct_write_verify_pct,
858-
sizeof (zfs_vdev_direct_write_verify_pct),
859-
param_set_direct_write_verify_pct, "IU",
860-
"Percentage of Direct I/O writes per top-level VDEV for checksum"
861-
" verification to be performed");
862-
/* END CSTYLED */
863-
864835
/*
865836
* Since the DTL space map of a vdev is not expected to have a lot of
866837
* entries, we default its block size to 4K.

0 commit comments

Comments
 (0)