Provide sf_buf_ref() to optimize refcounting of already allocated

sendfile(2) buffers.

Sponsored by:	Netflix
Sponsored by:	Nginx, Inc.
This commit is contained in:
Gleb Smirnoff 2014-08-11 12:59:55 +00:00
parent be71004959
commit 818d40d033
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269807
3 changed files with 23 additions and 2 deletions

View File

@ -201,6 +201,22 @@ sf_buf_free(struct sf_buf *sf)
mtx_unlock(&sf_buf_lock);
}
void
sf_buf_ref(struct sf_buf *sf)
{
#ifdef SFBUF_OPTIONAL_DIRECT_MAP
if (SFBUF_OPTIONAL_DIRECT_MAP)
return;
#endif
KASSERT(sf->ref_count > 0, ("%s: sf %p not allocated", __func__, sf));
mtx_lock(&sf_buf_lock);
sf->ref_count++;
mtx_unlock(&sf_buf_lock);
}
#ifdef SFBUF_PROCESS_PAGE
/*
* Run callback function on sf_buf that holds a certain page.

View File

@ -1993,8 +1993,7 @@ sf_ext_ref(void *arg1, void *arg2)
struct sendfile_sync *sfs = arg2;
vm_page_t pg = sf_buf_page(sf);
/* XXXGL: there should be sf_buf_ref() */
sf_buf_alloc(sf_buf_page(sf), SFB_NOWAIT);
sf_buf_ref(sf);
vm_page_lock(pg);
vm_page_wire(pg);

View File

@ -106,6 +106,7 @@ struct sf_buf;
#ifdef SFBUF
struct sf_buf *sf_buf_alloc(struct vm_page *, int);
void sf_buf_free(struct sf_buf *);
void sf_buf_ref(struct sf_buf *);
static inline vm_offset_t
sf_buf_kva(struct sf_buf *sf)
@ -168,6 +169,11 @@ static inline void
sf_buf_free(struct sf_buf *sf)
{
}
static inline void
sf_buf_ref(struct sf_buf *sf)
{
}
#endif /* SFBUF */
/*